I have three select boxes. When I select first select box,it automatically loads options of second and third select box using jQuery and AJAX (values from database).
But when I change the option of second select box,it should list the third select box values based on second select box option.But now I am getting select box options for third as 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() to empty the select box. But it doesn't reset the value.