i want to change the default value of dropdown list to 0 i.e selected index value shud become 0 when press the cancel button so that watever i selected previously is removed
i want it in javascipt only...i have done it in c#...since there s no forum for javascript i posted here only

here is the javsacript

function CloseDiv() {
            var control = document.getElementById("divReqStages");
            control.style.visibility = "hidden";
            var control1 = document.getElementById('DDLReqStages').selectedIndex;
            control1.value='0';
         
        }

here s the asp code....when i click here the drop down shud be reset

<input type="button" name="btnCancel" style="font-size: xx-small" onclick="JavaScript:CloseDiv();"  value="Cancel" />
<select id="DDLReqStages">
	<option>Option 1</option>
	<option>Option 2</option>
	<option>Option 3</option>
	<option>etc.</option>
</select>
<input type="button" name="btnCancel" style="font-size: xx-small" onclick="JavaScript:CloseDiv();"  value="Cancel" />
<script type="text/javascript">
   function CloseDiv() {
           // var control = document.getElementById("divReqStages");
           // control.style.visibility = "hidden";
           document.getElementById('DDLReqStages').selectedIndex = 0; // Reset
        }
</script>

<select id="DDLReqStages">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>etc.</option>
</select>
<input type="button" name="btnCancel" style="font-size: xx-small" onclick="JavaScript:CloseDiv();" value="Cancel" />
<script type="text/javascript">
function CloseDiv() {
// var control = document.getElementById("divReqStages");
// control.style.visibility = "hidden";
var ddlControl = document.getElementById('DDLReqStages');
ddlControl.value=0;//set the value of the item to be selected.
}
</script>

Did u get the solution ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.