|
-
Nov 27th, 2001, 03:31 AM
#1
Thread Starter
Frenzied Member
Selected option in JavaScript
How do I make an option selected using JavaScript function?
Code:
document.navform.serie.options.length = 4;
document.navform.serie.options[0].text = "Serie1";
document.navform.serie.options[0].value = "s1";
document.navform.serie.options[1].text = "Serie2";
document.navform.serie.options[1].value = "s2";
document.navform.serie.options[2].text = "Serie3";
document.navform.serie.options[2].value = "s3";
document.navform.serie.options[3].text = "Serie4";
document.navform.serie.options[3].value = "s4";
I want Serie1 to be selected
-
Nov 27th, 2001, 04:20 AM
#2
Fanatic Member
you mean like:
Code:
document.navform.serie.options[0].checked = true;
Blade
-
Nov 27th, 2001, 04:36 AM
#3
Thread Starter
Frenzied Member
No it is not a checkbox, so the code must be changed to
Code:
document.navform.serie.options[0].selected = true;
Thanks anyway
-
Nov 27th, 2001, 05:06 AM
#4
Fanatic Member
ummm, no.
it is checked not selected.
Test out the following HTML:
Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM Name="Test">
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R1>OPtion 1
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R2>OPtion 2
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R3>OPtion 3
</FORM>
<SCRIPT LANGUAGE=JAVASCRIPT>
document.Test.Radio1[0].checked= true;
</SCRIPT>
</BODY>
</HTML>
If you replace checked with selected, then it doesn't work.
Blade
-
Nov 27th, 2001, 05:08 AM
#5
Fanatic Member
the other way, of course it do:
Code:
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM Name="Test">
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R1 CHECKED>OPtion 1
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R2>OPtion 2
<INPUT TYPE="RADIO" NAME="Radio1" VALUE=R3>OPtion 3
</FORM>
</BODY>
</HTML>
Blade
-
Nov 27th, 2001, 05:12 AM
#6
Thread Starter
Frenzied Member
That's because you are using the RADIO. I am using a SELECT menu, and then it is SELECTED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|