简体   繁体   中英

drop down list changed

in my application I need to check if a drop down list has changed or not. can you please let me know how I should write it?

if (document.form.dropdownlist.???) 

I don't know what to write instead of ????

You could give this dropdownlist an unique id:

<select name="foo" id="foo">
    ...
</select>

and then subscribe for the onchange event (make sure you make the subscription once the DOM is loaded, for example in the body onload method):

var ddl = document.getElementById('foo');
ddl.onchange = function() {
    alert('the value has changed');
};
var count=3;

 function check()
 {
    var obj =new Array();
    obj=document.getElementById("list");
    checkLength(obj.length);
 }
 function checkLength(len)
 {
    if(len>count)
    {
       alert("Drop down size changed");
    }
 }
  • Take three option elements in select element.
  • Call the method check() using onchange() to get the size of drop down list.
  • The variable count is used to store the drop down list size .
  • So that it can be used to check if drop down list is changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM