0

Can someone tel me the code to put a dropdown box showing default values as shown below using script ..i,e by enclosing them in document.write in script

<CODE>

<SELECT NAME="choice" >
<OPTION VALUE="1">one </OPTION >
<OPTION VALUE="2">two </OPTION >
<OPTION SELECTED VALUE=" 5 "> 5 </OPTION>
</SELECT>

</CODE>

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Shanti C
0

this:

<script type="text/javascript">
document.write("<SELECT NAME=\"choice\" >"+
		"<OPTION VALUE=\"1\">one </OPTION >"+
		"<OPTION VALUE=\"2\">two </OPTION >"+
		"<OPTION SELECTED VALUE=\"5\"> 5 </OPTION>"+
		"</SELECT>");
</script>
0

thanz!That was the case of a constant..whats the case of variable? like now incase its a counter variable i need to show as default selected in a drop down box or the selected value changes dynamically according to some conditon....for example now i need to print a for loop counter variable's value as the selected option if a condition satisfies..

<script type="text/javascript">
document.write("<SELECT NAME=\"choice\" >")
for (var counter=0; counter<10;counter++)
{
if(counter==6)
{<!-- display as selected option-->
 }
else
{ <!-- display as an option in the dropdown box-->
}
}
document.write("</SELECT>");

</script>
0

thanz!That was the case of a constant..whats the case of variable? like now incase its a counter variable i need to show as default selected in a drop down box or the selected value changes dynamically according to some conditon....for example now i need to print a for loop counter variable's value as the selected option if a condition satisfies..

<script type="text/javascript">
document.write("<SELECT NAME=\"choice\" >")
for (var counter=0; counter<10;counter++)
{
if(counter==6)
{<!-- display as selected option-->
 }
else
{ <!-- display as an option in the dropdown box-->
}
}
document.write("</SELECT>");

</script>
0

then:

<script type="text/javascript">
document.write("<SELECT NAME=\"choice\" >")
for (var counter=0; counter<10;counter++)
{
if(counter==6)
{
document.write("<OPTION VALUE=\""+counter+"\" selected>"+counter+"</OPTION >");
 }
else
{ document.write("<OPTION VALUE=\""+counter+"\">"+counter+"</OPTION >");
}
}
document.write("</SELECT>");

</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.