Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting an Option Programmatically 1

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
US

I want to select a selection object programmatically. I have two radio buttons: single for a single date and range for a range of dates. When the user clicks a button, I want to programmatically select the single date radio button.

I currently have this code, but it doesn't seem to be working:

function today_onclick()
{
document.req_cdate.date[1].selected = "1"
}

I'm not getting a syntax error, it's just not doing anything.

Can anybody help me out here?

Thanks,
Ann


 
I think I'm confused. Do you want to programmatically select an item from a select (drop down) list, or a radio button? Here's the code to do whichever:
Code:
// select an option
document.formname.selectname[index].selected = true;
// select a radio button
document.formname.radioname[index].checked = true;
The problem may be that you're using "1". I'm not sure that's the same as using a numeric 1, and it may not be evaluating to true. I prefer to use true and false instead. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I'm trying to select a radio button and that didn't work. I'm not sure what I'm doing wrong. My radio buttons are set up like this:

<input type=radio name=&quot;date&quot; value=&quot;single&quot; onclick=&quot;date_entry()&quot;> Search for one date

<input type=radio name=&quot;date&quot; value=&quot;range&quot; onclick=&quot;range_entry()&quot;> Search for a range of dates

And the code I used, adapted from your post:

function today_onclick()
{
document.req_cdate.date[1].selected = true;
//req_cdate.enter_date.disabled=false;
}

What am I missing?

Thanks,
Ann


 
For radio buttons you have to use &quot;checked&quot; instead of selected. Also, the FIRST radio button has an array index of ZERO. So change the line in your function to:
Code:
document.req_cdate.date[0].checked = true;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Doh! I should go back to kindegarten to learn how to follow instructions properly. (I'm a technical writer, I should know better!)

Thank you so much. That worked perfectly.

Ann
 
You're welcome. Thanks for the chuckle I got from your response. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top