If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Get VALUE from checked radio button?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-03, 13:16
buzzter66 buzzter66 is offline
Registered User
 
Join Date: Nov 2002
Location: Houston, Texas
Posts: 85
Get VALUE from checked radio button?

Dang. I just can't remember the syntax to do this.

My form is named "form1"
My radio button group is named "contactMeBy"

I want to get the value from the selected item so I can pass it to another field. I know there is a simple way to do this with Javascript, but my notes (and the book I got this tip from) are at home. Can anyone remember how to do it WITHOUT writing a function to loop through the array?

-----------------
E-mail: <input type="radio" name="contactMeBy" value="email">
Phone: <input name="contactMeBy" type="radio" value="phone" checked>
-----------------
This line is in a function tied to the SUBMIT button:
formContactMe = (document.all.form1.contactMeBy[something in here?].value);

Help is GREATLY appreciated!
Reply With Quote
  #2 (permalink)  
Old 06-04-03, 10:40
wakhy wakhy is offline
Registered User
 
Join Date: Jan 2003
Location: de/ro
Posts: 12
JS or ASP

If you submit the form the value of the group contactMeBy will be the one which is selected.
The Request.Form("contactMeBy") will return "email" in case the email radio button is checked.

If you want to access the values of the radios from the group contactMeBy into JS, you'll have to use the indexes of the items from the group; like document.all.form1.contactMeBy[0].value refers to the value of the first radio in the group; the returned value will be "email". The document.all.form1.contactMeBy[1].value returns "phone".
You can loop through the items of the group using the length attribute of the group returning the number of children.
For example:

<script language="JavaScript">
<!--
for (i = 0 ; i < document.all.form1.contactMeBy.length ; i++)
{
alert(document.all.form1.contactMeBy[i].value + " is " +document.all.form1.contactMeBy[i].checked);
}
//-->
</script>


I hope that helps.
.:wakhy:.
Reply With Quote
  #3 (permalink)  
Old 06-04-03, 18:05
buzzter66 buzzter66 is offline
Registered User
 
Join Date: Nov 2002
Location: Houston, Texas
Posts: 85
Thanks!

Thanks for the detailed description. It was useful, but I had to adapt it. I didn't want to loop through it and see which was checked, I just wanted to return the VALUE of the one that was checked.

I actually just hard-coded it all (had to get it out today). I just wrote a function that manually changes the variable when the radio button is clicked.

Thanks again for the help, though. Ihave filed this info -- I'm sure I'll use it eventually.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On