当前位置: 动力学知识库 > 问答 > 编程问答 >

html - How to call a JavaScript function onchange of a 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 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?

网友答案:

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;
}
网友答案:

actually there is a " missing there, it should be >>

onChange="checkit();"
网友答案:

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.

网友答案:

by id jquery-1.9.1

$('#selectBox').on('change', function() 
{
    value= this.value;
    if(value==0)
      {
        //code
      }
    else if(value==1)
      {
         //code
      }
     ...
     else
      {
         //code
      }
  });
分享给朋友:
您可能感兴趣的文章:
随机阅读: