Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Form Field Onchange or Onclick - how to call Javascript function

Started by Michal Koza 7 years ago · 1 replies · 3672 views
7 years ago

To hide/unhide fields in HTML I am using styles and javascript function, called by 'onchange' or 'onclick':
<input id="users" type="radio"..... onclick="MyFunction();"/>

Now I'm trying to create dynamic form with Form plugin, where some fields will get hidden or not, based on radiobutton selection.

Can you tell me , how can I call Javascript within Form plugin, when radiobutton is clicked ( or value of field is changed)?

7 years ago

SOLVED

Script:

document.getElementById('myid').onclick = MyFunction;

did the job.
In this case Javascript must be renderd after content. Othervise it is possible to use JQuery script:

JS
$(document).ready(function() {
    $('#myid').change(MyFunction);
});

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by TomW, 3 weeks ago
3 277 3 weeks ago
Forms & Blueprints · by Japhy, 1 month ago
2 526 1 month ago
Forms & Blueprints · by FrViPofm, 2 months ago
5 522 2 months ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2516 9 months ago
Forms & Blueprints · by Hugo Oliveira, 10 months ago
0 958 10 months ago