/    Sign up×
Community /Pin to ProfileBookmark

Still Having Issues Referencing <select> options…

Could anyone tell me what could be the problem with using this line of code:

[CODE]
<script type=”text/javascript”>
[COLOR=”Blue”]var the_select1 = document.getElementById(“type_socks”);
var sock_selection1 = the_select1.options[the_select1.selectedIndex].value;[/COLOR]

function someThing(){

something that references the select value…

}

</script>
[/CODE]

The object is being called in the global scope and I keep getting ‘null’ and ‘undefined’ values out of error console and firebug…what could possibly be the issues here?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameFeb 18.2009 — Try:

var sock_selection1 = the_select1.options[the_select1.[COLOR="Red"]options[/COLOR].selectedIndex].value;
Copy linkTweet thisAlerts:
@banksworld1986authorFeb 18.2009 — Try:

var sock_selection1 = the_select1.options[the_select1.[COLOR="Red"]options[/COLOR].selectedIndex].value;[/QUOTE]


Okay, I tried that and I also tried window.onload...it looks something like:

[CODE]
<script type="text/javascript">

window.onload = function(){
the_div = document.getElementById("the_errors");
the_select1 = document.getElementById("type_socks");
sock_selection1 = the_select1.options[the_select1.selectedIndex].value;
the_select2 = document.getElementById("type_polish");
polish_selection1 = the_select2.options[the_select2.selectedIndex].value;
the_select3 = document.getElementById("sock_sel");
sock_selection2 = the_select3.options[the_select3.selectedIndex].value;
the_select4 = document.getElementById("polish_sel");
polish_selection2 = the_select4.options[the_select4.selectedIndex].value;
}

function someThing{

something that references the select tag values
}
</script>
[/CODE]


and Firebug as it steps through the code is giving me "" values for the select values...?...even though something is selected and the html looks like: <select><option value="something">...</option></select>..this is pretty frustrating...:rolleyes:
Copy linkTweet thisAlerts:
@banksworld1986authorFeb 18.2009 — Try:

var sock_selection1 = the_select1.options[the_select1.[COLOR="Red"]options[/COLOR].selectedIndex].value;[/QUOTE]


Okay...

I solved it...

I used [CODE]
var sock_selection1 = the_select1.options[the_select1.selectedIndex].[COLOR="Blue"]innerHTML[/COLOR]...
[/CODE]


Thanks
×

Success!

Help @banksworld1986 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.12,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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