Reset Select box values using jquery -
i have 3 select boxes.when select first select box,it automatically loads options of second , third selectbox using jquery , ajax( values database).
but when change option of second select box,it should list third select box values based on second select box option.but getting select box options third per first option.
$(document).ready(function() { $("#cat").change(function() { var pc_id = $(this).val(); if(pc_id != '') { $.ajax ({ type: "post", url: "load_sub_cats.php", data: "catid="+ pc_id, success: function(option) { $("#subcat").html(option); } }); } else { $("#subcat").html("<option value=''>-- no category selected --</option>"); } if(pc_id != '') { $.ajax ({ type: "post", url: "load_qset.php", data: "catid="+ pc_id, success: function(option) { $("#questionset").html(option); } }); } else { $("#questionset").html("<option value=''>-- no question set selected--</option>"); } return false; }); $("#subcat").change(function() { var pc_id = $(this).val(); //$("#questionset").html("<option value=''>-- select question set --</option>"); $("#questionset").empty(); if(pc_id != '') { $.ajax ({ type: "post", url: "load_subcat_qset.php", data: "subcatid="+ pc_id, success: function(option) { $("#questionset").html(option); } }); } else { $("#questionset").html("<option value=''>-- no question set selected --</option>"); } return false; }); });` i have used empty() empty select box.but doesnt reset value.
regards, rekha
instead of empty(), try this:
$('#questionset') .find('option') .remove() .end() .append('<option value="whatever">text</option>') .val('whatever') ; see this post more details
Comments
Post a Comment