How to count the number of options in select using jquery -
i want compare number of items in 2 select elements(html). tried using length property(with jquery) says both select element have number of option =1. populating both select elements dynamically. do?
var $options=$("#test_select"); $options.empty(); $.each(t_test_list,function(index,value){ $options.append($("<option>").text(value).attr("value",value)); }); var numdate=$("#date_select").length; var numtest=$("#test_select").length; alert(numdate); alert(numtest); if(numdate!=numtest) { alert("the number of dates not match test cases!!!"); }
try this:
change:
var numdate=$("#date_select").length; var numtest=$("#test_select").length;
to:
var numdate=$("#date_select").children('option').length; var numtest=$("#test_select").children('option').length;
you need options length children of select not select length.
Comments
Post a Comment