471,350 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

autofil a radio button

Jay
I have a form used to submit data (no surprises there!).
I'd like to be able to populate the same form with previously submitted
data.

The data lives in a database once submitted and using ASP I can populate
text boxes/textareas using this data no problem.
What about radio buttons?

If I have 2 of them named the same rb1 and rb1 with values of yes/no
respectively.
How can I check the one that was initially checked?

Cheers

J
Jul 23 '05 #1
4 3066
Jay wrote:
I have a form used to submit data (no surprises there!).
I'd like to be able to populate the same form with previously submitted
data.

The data lives in a database once submitted and using ASP I can populate
text boxes/textareas using this data no problem.
What about radio buttons?

If I have 2 of them named the same rb1 and rb1 with values of yes/no
respectively.
How can I check the one that was initially checked?


<input type="radio" checked>This one is checked
<input type="radio">This one is not checked.

--
Randy
Jul 23 '05 #2
Jay

"Randy Webb" <Hi************@aol.com> wrote in message
news:-I********************@comcast.com...
Jay wrote:
I have a form used to submit data (no surprises there!).
I'd like to be able to populate the same form with previously submitted
data.

The data lives in a database once submitted and using ASP I can populate
text boxes/textareas using this data no problem.
What about radio buttons?

If I have 2 of them named the same rb1 and rb1 with values of yes/no
respectively.
How can I check the one that was initially checked?
<input type="radio" checked>This one is checked
<input type="radio">This one is not checked.


Thanks Randy.
I know how to check a button but what I want to do is read the info from the
database and then populate a form based on those values.
For the text boxes I will use....(asp)
<input type = text name = "foo" value="<%=rs("BarValue")%>">
I'm not sure how to check a given radio button based on the info from the
database....

database contains the value "yes"
I have 2 radio buttons (values are "no" and "yes") therefore the form should
have "yes" checked as this was the value.
Next time it may be "no" in which case the radio button with the value of
"no" should be checked onLoad

Jay

--
Randy

Jul 23 '05 #3
Jay wrote:
"Randy Webb" <Hi************@aol.com> wrote in message
news:-I********************@comcast.com...
Jay wrote:
I have a form used to submit data (no surprises there!).
I'd like to be able to populate the same form with previously submitted
data.

The data lives in a database once submitted and using ASP I can populate
text boxes/textareas using this data no problem.
What about radio buttons?

If I have 2 of them named the same rb1 and rb1 with values of yes/no
respectively.
How can I check the one that was initially checked?


<input type="radio" checked>This one is checked
<input type="radio">This one is not checked.

Thanks Randy.
I know how to check a button but what I want to do is read the info from the
database and then populate a form based on those values.
For the text boxes I will use....(asp)
<input type = text name = "foo" value="<%=rs("BarValue")%>">
I'm not sure how to check a given radio button based on the info from the
database....

database contains the value "yes"
I have 2 radio buttons (values are "no" and "yes") therefore the form should
have "yes" checked as this was the value.
Next time it may be "no" in which case the radio button with the value of
"no" should be checked onLoad


Have ASP check the value of the Radio Button. Then check the appropriate
one.

Client-side, convert it to ASP:

if (radioButtonValue == "yes")
{
//ASP code to generate the Radio buttons with the Yes
//button checked
}
else
{
//ASP code to generate the Radio buttons with the No
//button checked
}

--
Randy
Jul 23 '05 #4
Jay wrote:
I know how to check a button but what I want to do is read the info from
the database and then populate a form based on those values.
For the text boxes I will use....(asp)
<input type = text name = "foo" value="<%=rs("BarValue")%>">
I'm not sure how to check a given radio button based on the info from the
database....

database contains the value "yes"
It should contain the (SQL) boolean values TRUE (and FALSE) instead.
I have 2 radio buttons (values are "no" and "yes") therefore the form
should have "yes" checked as this was the value.
Next time it may be "no" in which case the radio button with the value of
"no" should be checked onLoad


Child's play. Since you appear to use ASP:

<%@ LANGUAGE = JScript %>
...
<%
var bYesNo = rs("BarValue"); // using Boolean data
or
var bYesNo = (rs("BarValue") == "yes"); // using String data
%>
...
<input type="radio" name="foo"
value="Yes"<%= (bYesNo ? " checked" : "") %>>Yes
<input type="radio" name="foo"
value="No"<%= (!bYesNo ? " checked" : "") %>>No
HTH

PointedEars
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Oscar Monteiro | last post: by
5 posts views Thread by Digital Puer | last post: by
3 posts views Thread by John Davis | last post: by
8 posts views Thread by David Cameron | last post: by
9 posts views Thread by IchBin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.