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 · 3760 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 Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago