Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Using variables in DOM objects
Old 12-08-2006, 09:41 PM Using variables in DOM objects
Super Talker

Posts: 116
Trades: 0
Hi there,

I'm working on a JavaScript function for a form.

My form is a survey with about four groups of radio buttons.

I want to create one function that I can return the value from one of the radio button groups by passing the name of the radio button group as a variable.

Here's a sample of the code to get the value of a radio group called "concerts" WITHOUT passing the radio group variable.

function get_radio_value()
{
for (var i = 0; i < document.orderform.concerts.length; i++)
{
if (document.orderform.concerts[i].checked)
{
var rValue = document.orderform.music[i].value;
}
}
}

I want to be able to use the above code for ALL my button groups by passing:
get_radio_value("concerts")

Would I have to use the EVAL function in some way?

Thanks
Donna
DonnaZ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-09-2006, 10:49 AM Re: Using variables in DOM objects
Novice Talker

Posts: 9
Location: Russian Federation
Trades: 0
Try to make something like in this sample:
Code:
 
function getRadioValue (name) {
  var radioGroup = document.forms.orderform[name];
  for (var i = 0; i < radioGroup.length; i++) {
    if (radioGroup[i].checked) {
      var rValue = document.orderform.music[i].value;
    }
  } 
}
The call of function will look like:
Code:
 
getRadioValue ('concerts')
_ru_ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using variables in DOM objects
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10084 seconds with 12 queries