Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Form Field Onchange or Onclick - how to call Javascript function

Started by Michal Koza 7 years ago · 1 replies · 3189 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 Ton Haarmans, 5 years ago
13 1139 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 137 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 112 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 131 7 months ago