Reputation: 865
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 checkit()
function in it from below <select>
tag:
<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 select box should be disabled. Can anyone tell me where I went wrong?
Upvotes: 4
Views: 78127
Reputation: 66
document.querySelector("select").onchange = function() {myFunction()};
Upvotes: 1
Reputation: 97
actually there is a " missing there, it should be
onChange="checkit();"
Upvotes: 5
Reputation: 11
by id jquery-1.9.1
$('#selectBox').on('change', function()
{
value= this.value;
if(value==0)
{
//code
}
else if(value==1)
{
//code
}
...
else
{
//code
}
});
Upvotes: 1
Reputation: 862
I needed to put its javascript function before the input tag is generated.
EG.outside jourJSframework(document).ready function or before the <\head> closing tag of your html document.
Upvotes: 0
Reputation: 31458
Change the onchange
to onChange="checkit(this);
and then something like the below in checkit
function checkit(selectObj)
{
var idx = selectObj.selectedIndex;
document.frm.Month.disabled = idx == 0;
}
Upvotes: 3