function checkit() { var state=...">

How to call JavaScript function when replacing select tag?

Below is my javascript:

<script language="JavaScript"> function checkit() { var state=document.frm.getElementById(stateS) if (state="Please select a state") { document.frm.Month.disable = true; } else { document.frm.Month.enable = true; } }</script> 

and I call the checkit() function in it below the <select> :

 <td align="left"><g:select name="Month" from="${month.values()}" optionValue="${Month}" onChange=checkit()/></td> </tr> 

I have a select tag for state, and until I select any state, the month selection field should be disabled. Can someone tell me where I was wrong?

+4
source share
5 answers

actually there is a “missing” it should be

 onChange="checkit();" 
+3
source

Change onchange to onChange="checkit(this); and then something like below in checkit

 function checkit(selectObj) { var idx = selectObj.selectedIndex; document.frm.Month.disabled = idx == 0; } 
+2
source

by id jquery-1.9.1

 $('#selectBox').on('change', function() { value= this.value; if(value==0) { //code } else if(value==1) { //code } ... else { //code } }); 
+1
source

I needed to put its javascript function before creating the input tag.
EG.outside jourJSframework (document) .ready or before the closing tag <\ head> of your html document.

0
source

document.querySelector("select").onchange = function() {myFunction()};

0
source

All Articles