/    Sign up×
Community /Pin to ProfileBookmark

Frustrated with listboxes in IE

I have this function that works perfectly well in Firefox but failes in IE. It’s suppouse to read a text value of the option and then stick it into the hidden field.

Any ideas how to make it work in both browsers ?

[code]
function agentNameFunc(){
var agentNameVar=agent.options[agent.selectedIndex].text;
var campNameVar=project.options[project.selectedIndex].text;
document.getElementById(“agentName”).value=agentNameVar;
document.getElementById(“projectName”).value=campNameVar;
}
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 28.2006 — This assumes a certain default scoping:

var agentNameVar=agent.options[agent.selectedIndex].text;

Different browsers have a different default scoping depending upon the context.

If you have a FORM tag then, cross-browser, the above should be as follows:

var agentNameVar=document.myFormName.agent.options[document.myFormName.agent.selectedIndex].text;
Copy linkTweet thisAlerts:
@difrad76authorJun 28.2006 — thanks
Copy linkTweet thisAlerts:
@phpnoviceJun 28.2006 — You're welcome.

Cheers.
×

Success!

Help @difrad76 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...