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
Calling DOM objects with variables
Old 12-08-2006, 09:37 PM Calling DOM objects with variables
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"

function get_radio_value()
{
for (var i = 0; i < document.orderform.music.length; i++)

}
DonnaZ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-09-2006, 10:17 PM Re: Calling DOM objects with variables
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by DonnaZ View Post
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"

function get_radio_value()
{
for (var i = 0; i < document.orderform.music.length; i++)

}

Code:
function get_radio_value( group ) /* For simplicity, assumes at least 2 buttons in group*/
{
  for (var i = 0; i < group.length && !group[i].checked; i++)
  ;

  return i==group.length ? "" : group[i].value;
}

get_radio_value(  document.orderform.music );
logic ali is offline
Reply With Quote
View Public Profile
 
Old 12-13-2006, 12:41 PM Re: Calling DOM objects with variables
Super Talker

Posts: 116
Trades: 0
Thanks a lot. I'll give it a go!
DonnaZ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Calling DOM objects with variables
 

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 1.72702 seconds with 12 queries