|
-
Jan 7th, 2002, 03:48 PM
#1
Thread Starter
Addicted Member
Setting Radio Buttons Value
I'm writing a script that has four radio buttons. They each have a value of A, B, C, and D. Now, I am pulling a letter value from a database using CGIREXX code (I don't expect anybody to know any CGIREXX) and I have the value, lets say "B" set to a variable. How do I initially set the default value of the radio button group to equal the radio button with the value of "B"? I read something about a defaultChecked property but I wasn't able to get it to work, if you know about this property and how to set it, or just a way to set the default value dynamically, please let me know. Thanks.
-
Jan 7th, 2002, 04:09 PM
#2
Hyperactive Member
At start up.
Code:
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="myform">
A<INPUT TYPE="radio" NAME="myoption">
B<INPUT TYPE="radio" NAME="myoption" CHECKED>
C<INPUT TYPE="radio" NAME="myoption">
D<INPUT TYPE="radio" NAME="myoption">
</form>
</body>
</html>
At runtime to check A, use
document.myform.myoption[0].checked = true;
-
Jan 7th, 2002, 04:15 PM
#3
Thread Starter
Addicted Member
that would work, I knew about the CHECKED thing that you can embed in the tag but I want to take a variable, and through JavaScript set it. I don't know which value is going to be checked each time so I need to set it dynamically.
I could use that document.form.options[x].checked line but I would need to run it through a loop to check if
document.form.options.value = myVariable
and if so then set the .checked to true. but isn't there a simplier way. To set a textbox you just say document.form.tBox.value = myVariable.
-
Jan 7th, 2002, 04:25 PM
#4
Hyperactive Member
No. there isn't a simple way as far as I know.. u have to loop through all the option box.
-
Jan 7th, 2002, 04:28 PM
#5
Thread Starter
Addicted Member
thanks, that won't be too hard to do. I was just being lazy, trying to find an easier way.
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
|