Click to See Complete Forum and Search --> : select tag
tiger66
07-16-2003, 04:15 PM
Hi
I am trying to select the the default value which is " " of a drop down list by using the javascript
document.myForm.mySelection.options[document.myForm.mySelection.options.selectedIndex].value = "";
but my default value doesn't get selected
Where have I done wrong?
Thanks
Khalid Ali
07-16-2003, 05:46 PM
without going into why its not working for you..try this
document.myForm.mySelection.options[0].value
tiger66
07-22-2003, 02:37 PM
I tried
document.myForm.mySelection.options[0].value
and
document.myForm.mySelection.options[0].value= ""
none of the above works, am I missing something?
Thanks
Khalid Ali
07-22-2003, 03:11 PM
Obviously there is some thing wrong with your code..here use this snippet
<script type="text/javascript">
<!--
function GetSelected(val){
alert("Value selected by user = "+val);
}
function Check(){
alert("First value in the list box = "+document.form1.listbox.options[0].value)
}
//-->
</script>
<body onload="Check();">
<form name="form1">
<select name="listbox" size="5" onclick="GetSelected(this.options[this.selectedIndex].value)">
<option value ="-1" selected="selected">Select one</option>
<option value ="1">one</option>
<option value ="2">Two</option>
</body>
tiger66
07-31-2003, 05:50 PM
Hi
I tried the following
document.myForm.mySelection.options[document.myForm.mySelection.options.selectedIndex].value = document.myForm.mySelection.options[0].value;
I used alert to check the value of
document.myForm.mySelection.options[document.myForm.mySelection.options.selectedIndex].value
and it gets assigned to the first value but the option doesn't get selected.
Am I missing a step?
Thanks
This:
document.myForm.mySelection.options[document.myForm.mySelection.options.selectedIndex].value
should be:
document.myForm.mySelection.options[document.myForm.mySelection.selectedIndex].value
tiger66
07-31-2003, 06:12 PM
Hi
I tried
document.myForm.mySelection.options[document.myForm.mySelection.selectedIndex].value = document.myForm.mySelection.options[0].value;
it still didn't fix my problem. Why???
tiger66
08-01-2003, 02:35 PM
Hi
Can someone please help me with the code below? I am trying to use a button to select the first option
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function selected()
{
//alert(document.myForm._1_1_124_1.options[document.myForm._1_1_124_1.selectedIndex].value);
alert(document.myForm._1_1_124_1.options[0].value);
document.myForm._1_1_124_1.options[document.myForm._1_1_124_1.selectedIndex].value = ""
}
</script>
</head>
<body>
<form action="" name="myForm">
<LABEL FOR="_1_1_124_1"></LABEL>
<SELECT ID="_1_1_124_1" NAME="_1_1_124_1">
<OPTION VALUE="" ><None></OPTION>
<OPTION VALUE="red" >Red</OPTION>
<OPTION VALUE="blue" >Blue</OPTION>
<OPTION VALUE="green" >Green</OPTION>
</SELECT>
<input type="button" value="Apply" onClick="selected()">
</form>
</body>
</html>
Exuro
08-01-2003, 02:50 PM
I'm not sure what you're trying to do... But maybe this is what you're looking for:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function selected()
{
//alert(document.myForm._1_1_124_1.options[document.myForm._1_1_124_1.selectedIndex].value);
//alert(document.myForm._1_1_124_1.options[0].value);
document.myForm._1_1_124_1.selectedIndex = 0;
}
</script>
</head>
<body>
<form action="" name="myForm">
<LABEL FOR="_1_1_124_1"></LABEL>
<SELECT ID="_1_1_124_1" NAME="_1_1_124_1">
<OPTION VALUE="" ><None></OPTION>
<OPTION VALUE="red" >Red</OPTION>
<OPTION VALUE="blue" >Blue</OPTION>
<OPTION VALUE="green" >Green</OPTION>
</SELECT>
<input type="button" value="Apply" onClick="selected()">
</form>
</body>
</html>