/    Sign up×
Community /Pin to ProfileBookmark

problem using selectedIndex

Hi all,

I am trying to use javascript to force my select list to default to option 10.
It seems to work fine in IE :rolleyes: , but not Firefox. Firebug says “s has no properties”

Any ideas? I’m sure its something simple. Here is the code:

function getIndex()
{
var x=document.getElementById(“F046pcode3”)
x.selectedIndex=10
}

Thanks

Stu

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@yearbassNov 28.2007 — x.options[10].selected=true
Copy linkTweet thisAlerts:
@ignazzz_calmNov 28.2007 — my answer is same like yearbass brother...

that good answer my brother.... i agree with you.
Copy linkTweet thisAlerts:
@mrhooNov 28.2007 — I have to agree with firefox- your code doesn't have any [B]s[/B].
Copy linkTweet thisAlerts:
@sureauthorNov 28.2007 — sorry for the typo - should read "x has no properties"

anyway's

I tried the code yearbass suggested and FF didnt like that either:

function getIndex()

{

var x=document.getElementById("F046pcode3")

x.options[10].selected=true

}
Copy linkTweet thisAlerts:
@sureauthorNov 28.2007 — solved - I used:

function getIndex()

{

document.forms[0].F046pcode3.options[10].selected= true;

}

thanks for the help guys
×

Success!

Help @sure 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...