I want to reset childcombo box after disabled by parent combo. Child combo box is being disabled when i am selecting select option in parent combo box. After populating child combo box if i am selecting select option in parent combo, child combo is going to be disabled but how to reset child combo at this time that is child combo will also show please select option? What i need to add in javascript?
<script type="text/javascript">
$(document).ready(function() {
$(function(){
var arrVal = ["RS", "MN", "KL"];
$("#parentcombo").change(function(){
var valToCheck = String($(this).val());
if ( jQuery.inArray(valToCheck,arrVal) == -1 )
{
$("#childcombo").attr("disabled", "true");
}
else
{
$("#childcombo").removeAttr ( "disabled" );
}
});
});
});
</script>
HTML
<select id="parentcombo">
<option value="_">select</option>
<option value="RS">RS</option>
<option value="MN">MN</option>
<option value="KL">KL</option>
</select>
<select id="childcombo" disabled="true">
<option value="_">please select</option>
<option value="somevalue">somevalue</option>
<option value="somevalue1">somevalue1</option>
<option value="somevalue2">somevalue2</option>
</select>
Use
$('#childcombo').val("_")to select"please select"option in child combo box.If you want to select any option in
selectelement useval()method and pass the optionvalueto it, it will select thatoption.In your case since you want to select
"please select"option in child combo box we used its value"_"to pass toval()method.Alternative way using pure javascript is to set
selectedIndexproperty of the select element.