Forums
This topic is locked
Help with Radio Button Values
11 Feb 2005 21:37:08 A. B. posted:
Hello. I am pretty new to ASP and am learning to code it myself. I am having problems though with displaying the selected radio button value. For example, the radio buttons are coded as follows in the edit.asp page:<input type="radio" name="f24" value="1">Yes<br>
<input type="radio" name="f24" value="0">No
Even though the data exists in the SQL Server 7 db (as a bit type), the radio button is not selected that corresponds to the data in the db. How do I code so the correct radio button is selected?
I retrieve and display text data using this code:
<nput name="f14" type="text" size="30" maxlength="50" value="<%Response.Write rsRestaurants.Fields("OperationHoursSun".Value%>">
What code do I use to select the correct radio button?
Thank you in advance for your help!
Andrea
Replies
Replied 11 Feb 2005 22:07:11
11 Feb 2005 22:07:11 Rene Bandsma replied:
What does the database return if you show the result of your code?
<pre id=code><font face=courier size=2 id=code>
<%=rsRestaurants.Fields("OperationHoursSun".Value%>
</font id=code></pre id=code>
And I assume that you are using a radio group because of the same name? Then you should use an simple IF construction. When the OperationHoursSun has value 0 then show this rule: "<input name="RadioGroup1" type="radio" value="radio" checked>".
<pre id=code><font face=courier size=2 id=code>
<%=rsRestaurants.Fields("OperationHoursSun".Value%>
</font id=code></pre id=code>
And I assume that you are using a radio group because of the same name? Then you should use an simple IF construction. When the OperationHoursSun has value 0 then show this rule: "<input name="RadioGroup1" type="radio" value="radio" checked>".
Replied 11 Feb 2005 22:54:49
11 Feb 2005 22:54:49 A. B. replied:
THank yuou, Rene, for your quick response. This is what I have now for the code:
<input type="radio" name="f23" value="1">Yes<br>
<input type="radio" name="f23" value="0">No
<%
If rsRestaurants.Fields("BanquetRooms".Value = "1" Then
Response.Write "<input name='BanquetRooms' type='radio' value='1' checked>"
Else
Response.Write "<input name='BanquetRooms' type='radio' value='0' checked>"
End If
%>
When the results appear now, a third radio button, which is selected, appears to the right of the "No" text. I don't know how to preselect one of the displayed radio buttons based on the value in the db.
Would you please help me with this again?
Thanks!
Andrea
<input type="radio" name="f23" value="1">Yes<br>
<input type="radio" name="f23" value="0">No
<%
If rsRestaurants.Fields("BanquetRooms".Value = "1" Then
Response.Write "<input name='BanquetRooms' type='radio' value='1' checked>"
Else
Response.Write "<input name='BanquetRooms' type='radio' value='0' checked>"
End If
%>
When the results appear now, a third radio button, which is selected, appears to the right of the "No" text. I don't know how to preselect one of the displayed radio buttons based on the value in the db.
Would you please help me with this again?
Thanks!
Andrea
Replied 13 Feb 2005 15:49:10
13 Feb 2005 15:49:10 Rene Bandsma replied:
Hello Andrea,
I've created a little code example for you:
<pre id=code><font face=courier size=2 id=code>
<% FieldValue = "1" %>
<% If FieldValue = "1" Then %>
<p>
<label><input name="f23" type="radio" value="1" checked>Yes</label>
<br>
<label><input type="radio" name="f23" value="0">No</label>
<br>
</p>
<% ELSE %>
<p>
<label><input type="radio" name="f23" value="1">Yes</label>
<br>
<label><input name="f23" type="radio" value="0" checked>No</label>
<br>
</p>
<% END IF %>
</font id=code></pre id=code>
If you change my FieldValue to your recordset value: rsRestaurants.Fields("BanquetRooms".Value everything should work fine! The code above is not optimized and I'm sure there are lots of way to program it more efficiently. But the above code is easy to read for the eye and understandable.
Good luck!
I've created a little code example for you:
<pre id=code><font face=courier size=2 id=code>
<% FieldValue = "1" %>
<% If FieldValue = "1" Then %>
<p>
<label><input name="f23" type="radio" value="1" checked>Yes</label>
<br>
<label><input type="radio" name="f23" value="0">No</label>
<br>
</p>
<% ELSE %>
<p>
<label><input type="radio" name="f23" value="1">Yes</label>
<br>
<label><input name="f23" type="radio" value="0" checked>No</label>
<br>
</p>
<% END IF %>
</font id=code></pre id=code>
If you change my FieldValue to your recordset value: rsRestaurants.Fields("BanquetRooms".Value everything should work fine! The code above is not optimized and I'm sure there are lots of way to program it more efficiently. But the above code is easy to read for the eye and understandable.
Good luck!
Replied 13 Feb 2005 22:11:31
13 Feb 2005 22:11:31 A. B. replied:
Rene,
Thank you so much for your help! It works great! <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Andrea
Thank you so much for your help! It works great! <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Andrea
Replied 15 Feb 2005 00:19:41
15 Feb 2005 00:19:41 Lee Diggins replied:
Hi Andrea
In addition to Rene's excellent snippet, you can also evaluate the BIT datatype using true and false.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
In addition to Rene's excellent snippet, you can also evaluate the BIT datatype using true and false.
Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
Lee Diggins - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>
Replied 04 Aug 2006 16:10:46
04 Aug 2006 16:10:46 Willie Freer replied:
I am also trying to change the style (color and size) of radio button label. I have gone to the Radiobutton in the Library to try and edit it with little help.
Any ideas?
Thanks
Any ideas?
Thanks
Replied 05 Aug 2006 01:33:40
05 Aug 2006 01:33:40 Rene Bandsma replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
I am also trying to change the style (color and size) of radio button label. I have gone to the Radiobutton in the Library to try and edit it with little help.
Any ideas?
Thanks
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
You can just change the color and size of a radio button label tag by CSS. Just declare the right thing and manage everything in css. Sure you can also let Dreamweaver to the trick and select the text and change it the way you want to.
If you want to change for example the color depending on a database value then you could do something like this:
<%
IF RecordSet1.Fields.Item("agreed" = TRUE then color = "#FFFFFF"
IF RecordSet1.Fields.Item("agreed" = FALSE then color = "#00000"
%>
Add the radiobutton tag:
<input name="radiobutton" type="radio" value="radiobutton" style="color<%=color%>" />
<hr><b>DMXZone support manager</b><br><a href="www.kousman.nl">Kousman web resellers</a>
I am also trying to change the style (color and size) of radio button label. I have gone to the Radiobutton in the Library to try and edit it with little help.
Any ideas?
Thanks
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
You can just change the color and size of a radio button label tag by CSS. Just declare the right thing and manage everything in css. Sure you can also let Dreamweaver to the trick and select the text and change it the way you want to.
If you want to change for example the color depending on a database value then you could do something like this:
<%
IF RecordSet1.Fields.Item("agreed" = TRUE then color = "#FFFFFF"
IF RecordSet1.Fields.Item("agreed" = FALSE then color = "#00000"
%>
Add the radiobutton tag:
<input name="radiobutton" type="radio" value="radiobutton" style="color<%=color%>" />
<hr><b>DMXZone support manager</b><br><a href="www.kousman.nl">Kousman web resellers</a>