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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Option/Select with Internet Explorer

Status
Not open for further replies.

chrisb19

Programmer
Joined
Mar 6, 2006
Messages
2
Location
US
Hello all,

I'm trying to create dynamic options for a March Madness tournament that updates later rounds when someone selects a previous one. They work in Firefox but don't work in Internet Explorer.

Here's the code...

form_name = "re"+region+"_r"+round+"_g"+game;

if (document.forms['make_picks'].eval(form_name).options[slot].selected)
{
document.forms['make_picks'].eval(form_name).options[slot].value = team;
document.forms['make_picks'].eval(form_name).options[slot].text = '#'+team;
}

-form_name is the name of the particular select input for each game. Region, round, and game are all numbers that are input in the particular function I'm creating.
-This works great in Firefox. However, with IE, there is a problem with the eval(form_name) part.

Is there a better way to go about this?

Any help would be greatly appreciated.

Chris
 
There certainly is - and because it doesn't use eval, it will be faster, too. Replace this:

Code:
if (document.forms['make_picks'].eval(form_name).options[slot].selected)
{
document.forms['make_picks'].eval(form_name).options[slot].value = team;
document.forms['make_picks'].eval(form_name).options[slot].text = '#'+team;
}

with this:

Code:
var frmEl = document.forms['make_picks'].elements[form_name];
if (frmEl.options[slot].selected) {
	frmEl.options[slot].value = team;
	frmEl.options[slot].text = '#' + team;
}

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for the help! The pool will now be a heck of a lot nastier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top