Register  |  Login

Question Details    

   Question

Time: 12:14 - Feb 13, 2007     Asked by: jgivoni      Status: Answered      Points: 50   

How do I programmatically select a radio button?

I want to use javascript to set which of a group of radiobuttons will be selected.
Which method do I use?

Ask a New Question

Become a Quomon Expert

Current Categories

 

Other Questions Needing Answers


   

Answer Discussion
Answer Discussion
Answer Summaries
Answer Summary
 
jgivoni,

The way to select a radiobutton from within JavaScript is by iterating through the array that is created automatically when JavaScript encounters a radiobutton or checkbox type of input.

function setRadio()
{
var rad = document.getElementById(radiobutton);
for (i = 0; i < rad.length; i++)
{
// Perform appropriate test and then use
if (whatever)
{
rad[i].checked = true;
}
}
}

That should check the radio button you're expecting.

I hope this helps,
Ric

Expert:

rcastagna

Date:

Feb 16, 2007

Time:

07:58

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Hi Ric,

That works!
Actually I just needed this part:
buttonElement.checked = true

...as I already knew (by Id) which button I wanted to select.

You've answered my question, but I was wondering about your example... it seems to rely on document.getElementById to return an array... Is that correct?

Well, thanks anyway, i'll give you the points.

Jakob

Expert:

jgivoni

Date:

Feb 16, 2007

Time:

08:34

 

Votes: Good (0) | Bad (0)
Login to rate this answer

Question Answered

This question has been answered, and points have been rewarded to the following experts:

rcastagna: 50

You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.

 
No summaries have been submitted yet. Want to be the first?



Respond to this question:

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

 

New User

  Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:


Forgotten Password

   

"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it


All Questions


Language Options

English:

www.quomon.com

Español:

www.quomon.es

Quomon Blog

blog.quomon.com

Sponsors

Questions and Answers Software
Real Estate Postcards
Marketing Fulfillment