grabbing the value of a radio button (not an asp:radiobuttonlist)

D

darrel

I'm using some standard HTML radio buttons (to allow finer javascript
interaction) on a web page and would like to catch the selected item on
postback. Since they are all ID's uniquely, is there a way to grab only the
selected item's value? Or do I need to write an if/then statement to figure
out which one is selected?

Sample:

<input runat="server" id="radio1" name="category" />
<input runat="server" id="radio2" name="category" />
<input runat="server" id="radio3" name="category" />
<input runat="server" id="radio4" name="category" />
<input runat="server" id="radio5" name="category" />

-Darrel
 
A

Alejandro Penate-Diaz

if you add runat="server" then those radiobuttons are not html controls but
server controls, and are already bein posted back to the server so you can
reference them like this.radio1.selected == true
 
B

Bruce Barker

as the browser only posts back the name/value pair for a selected radio
button. so you need to set a unique value for each one.

<input type=radio id="radio1" name="category" value="1"/>
<input type=radio id="radio2" name="category" value="2"/>
<input type=radio id="radio3" name="category" value="3"/>
<input type=radio id="radio4" name="category" value="4"/>
<input type=radio id="radio5" name="category" value="5"/>

if radio2 is selected the browser will post category=2. you can check in the
selected value in the code behind by check Request.Form["category"]. it will
equal the value of the selected radio button.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top