Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Javascript: Grabbing value of a radio button
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

redbrad0
Advanced Member

USA
3725 Posts

Posted - 26 June 2004 :  12:54:50  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
I keep trying the below code and it always comes back as undefinded Is there something I am missing on is the Javascript?

alert(TravelForm.TravelPurpose.value);

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

proeder
Junior Member

Australia
230 Posts

Posted - 26 June 2004 :  13:43:21  Show Profile  Visit proeder's Homepage
What about

alert(document.travelform.travelpurpose.value);

Looking for german Snitz forum? Suchst Du ein deutsches Snitz Forum?
Hier findest Du eins...

Hosting with ASP Support available: http://www.sharepointing.com
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 26 June 2004 :  14:38:46  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Doesnt the case mess up in JS? The way I had it is the exact way the fields are used. If I grab the value of the textbox using the same code but changing the name (TravelPurpose) then it shows the value.

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 26 June 2004 :  19:05:35  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
quote:
Originally posted by proeder

What about

alert(document.travelform.travelpurpose.value);



When I try this I get a JS Error saying that it is null or not a object. I created a test.html page that shows the form. I am just trying to find out if they select in Question 15 if School Related Study/Work was selected so then I can validate and make sure they typed in "What School?". I am just trying to validate before going to ASP which I know I can validate it in ASP. Any other ideas?

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 27 June 2004 :  10:33:05  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
I just noticed that stupid me never gave a link to the test form.

<REMOVED LINK>

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets

Edited by - redbrad0 on 27 June 2004 18:52:52
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 27 June 2004 :  12:06:42  Show Profile
Did you try alert(document.TravelForm.TravelPurpose.value);

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 27 June 2004 :  12:11:19  Show Profile
you have to loop through the radio elements and see if they are checked, the one that is is the value you want to return.

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 27 June 2004 :  18:51:11  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Ok I figured it out. Here is what it said on a webpage about this...

quote:

The example determines which button is checked in each group and then displays the value in an alert box. We begin coding this example by making the two groups of radio buttons inside a <form>. I NAMEd the <form> "form1". Here's the code for the first group of "pet" buttons:

<h4>Favorite Pet</h4>

<input type="radio" name="pet" value="Dogs">Dogs<br>

<input type="radio" name="pet" value="Cats">Cats<br>

<input type="radio" name="pet" value="Birds">Birds<br>

<input type="radio" name="pet" value="Fish">Fish<br>

There are two important things to notice here. First, all of the radio buttons have the same NAME attribute -- "pet". This causes them to function as a group so that only one button can be selected at a time. It also sets the buttons up as a JavaScript array named "pet". The below would refer to the "Birds" button.

document.form1.pet[2]

The array is numbered beginning with zero. The assignment continues in the order in which the <input>s are coded. First coded is 0, next one is 1, etc.

The second thing to note is the use of a VALUE attribute. The VALUEs are all different. This is the data we can access with JavaScript. You cannot readily access the text labels of the radio buttons. We'll be dealing with the VALUE attribute's data.

document.form1.pet[0].value

The above would return a value of "Dogs". The "vegetable" radio button group is coded similarly. All of the "vegetable" buttons have the same name, so they'll work together as an array, but they all have different VALUEs coded into their <input> tags.

The whole goal here is to cycle through the array of radio buttons, find the checked one, and assign its VALUE to a variable for later use.


Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 2.83 seconds. Powered By: Snitz Forums 2000 Version 3.4.07