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

Posts: 109
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
 
When You Register, These Ads Go Away!
Old 12-09-2006, 10:49 AM Re: Using variables in DOM objects
Novice Talker

Posts: 9
Location: Russian Federation
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

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


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

 


Page generated in 0.11389 seconds with 12 queries