Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Still Having Issues Referencing <select> options...
Old 02-18-2009, 12:41 AM Still Having Issues Referencing <select> options...
Skilled Talker

Posts: 70
Location: Atlanta, GA
Trades: 0
Could anyone tell me what could be the problem with using this line of code:

Code:
<script type="text/javascript">
var the_select1 = document.getElementById("type_socks");
var sock_selection1 = the_select1.options[the_select1.selectedIndex].value;

function someThing(){

something that references the select value...

}

</script>
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?
LayneMitch is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-18-2009, 04:06 AM Re: Still Having Issues Referencing <select> options...
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
You've probably placed this code before the actual website.
So it tries to get an element with ID type_socks before that even exists.

You should wrap it in a function and call that function on window load.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 10:57 AM Re: Still Having Issues Referencing <select> options...
Skilled Talker

Posts: 70
Location: Atlanta, GA
Trades: 0
Quote:
Originally Posted by Insensus View Post
You've probably placed this code before the actual website.
So it tries to get an element with ID type_socks before that even exists.

You should wrap it in a function and call that function on window load.
Okay, I tried that and 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>
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...
LayneMitch is offline
Reply With Quote
View Public Profile
 
Old 02-18-2009, 01:10 PM Re: Still Having Issues Referencing <select> options...
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Because I can't see your full code I have to suggest the obvious things. :P
Do your <select> tags have an id=""? :P
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-19-2009, 08:56 AM Re: Still Having Issues Referencing <select> options...
Skilled Talker

Posts: 70
Location: Atlanta, GA
Trades: 0
Quote:
Originally Posted by Insensus View Post
Because I can't see your full code I have to suggest the obvious things. :P
Do your <select> tags have an id=""? :P
They do have an #id. Here I loaded the shopping cart page to this link:
http://www.ibtestsite.info

I'm not sure how you do it, but you can look at the JavaScript through Firebug. Since the my last post, I've referenced my <select> options like this:

Code:
var sock_sel = document.getElementById("type_socks");
var sock_style = sock_sel.options[sock_sel.selectedIndex].innerHTML;
At first it worked, but for some reason, now Firebug is giving me an error...

Last edited by LayneMitch; 02-19-2009 at 08:57 AM..
LayneMitch is offline
Reply With Quote
View Public Profile
 
Old 02-19-2009, 01:16 PM Re: Still Having Issues Referencing <select> options...
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
All I can think of, is adding a doctype, because any document.getElementById fails...
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Still Having Issues Referencing <select> options...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.93339 seconds with 12 queries