/    Sign up×
Community /Pin to ProfileBookmark

select+getelementbyId+ie7

hi

i was working with FireFox and than i wanted to see my code in IE7. Later i found out that
<html><body>
<select name=”Verkaufspreis” id=”price” size=”1″>
<option selected=”selected”>alle Preisklassen</option>
<option>200-400 Eur</option>
<option>400-600 Eur</option>
<option>600-800 Eur</option>
<option>800-1000 Eur</option>
</select>
</body></html>
var s1 = document.getElementById(‘price’).options[document.getElementById(‘price’).selectedIndex].value;

in IE7 not working. Though it was modified from document.getElementById(‘price’).value;

both have worked in FireFox.

where did i go wrong ?

thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliJul 19.2007 — 
<option selected="selected">alle Preisklassen</option>

<option>200-400 Eur</option>

<option>400-600 Eur</option>

<option>600-800 Eur</option>

<option>800-1000 Eur</option>

var s1 = document.getElementById('price').options[document.getElementById('price').selectedIndex].value;

in IE7 not working.
[/QUOTE]
This looks suspiciously like the classic "trying to read an option's value without assigning it one first" error.
Copy linkTweet thisAlerts:
@schiggyblastauthorJul 19.2007 — newbie question: why do i in IE7 have to bother to assign value in <option> to use the js-code i wrote, to make it work.... but in FireFox i don't have to to that to get the same correct answer ?

thanks though for your help logic ali.
Copy linkTweet thisAlerts:
@Logic_AliJul 19.2007 — newbie question: why do i in IE7 have to bother to assign value in <option> to use the js-code i wrote, to make it work.... but in FireFox i don't have to to that to get the same correct answer ?

thanks though for your help logic ali.[/QUOTE]
The text between option tags is stored in the .text property, which Mozilla chooses to copy to the .value property if none has been assigned.
Copy linkTweet thisAlerts:
@mrhooJul 20.2007 — There is a nice added incentive for assigning a value to an option in a select element-

You can read the select_element.options[select_element.selectedIndex].value directly from the select-

[B]var s1 = document.getElementById('price').value;[/B]

or if 'price' is a unique [B]name[/B], use

[B]var s1 = document.getElementsByName('price')[0].value;[/B]
×

Success!

Help @schiggyblast 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,
)...