Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in Code? 2

Status
Not open for further replies.

trojan800

Programmer
Nov 27, 2001
53
0
0
US
I have a dropdown box that when the onChange event is triggered it goes into the following javascript function:

var e_select = document.getElementById("hotel");
var hotel = new String(e_select.options[e_select.selectedIndex].value);

var strURL = new String ("border2.asp?page_id=51&h=" + hotel);
//var strURL = new String ("border2.asp?page_id=51&h=200");

result = location.href= strURL;

return result;

It essentially finds the value of the selected dropdown option , refreshes the page and passes that value to itself. This works fine in IE (as it usually accepts shotty code more often) but in Firefox and Netscape nothing happens. However if I comment out the first three lines and uncomment the 4th everything does work. So essentially I have to assume that something is wrong with the first three lines in my function and I need another pair of eyes to try and spot the problem. I hope that made sense and thanks for any and all help in advance.

-Rory
 
i think what you want is this;

Code:
var e_select = document.getElementById("hotel");
var hotel = e_select.options[e_select.selectedIndex].value;
var strURL = "border2.asp?page_id=51&h=" + hotel;
    
result = strURL;
return result;

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thanks Flava, but still nothing... anything else?
 
show what you're trying to do with the code. you haven't explained that yet.

It essentially finds the value of the selected dropdown option , refreshes the page and passes that value to itself

what does that mean?

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Sorry, I will try to be more clear... There is a dropdown box called 'hotel' on the page and when the user selects a value from the dropdown, the onChange event is triggered which calles the javascript function in question. This functions purpose it is to find that value selected in the select box 'hotel' and then refresh the page, sending with it the selected value. The page then uses request.querystring to extract the value that was passed. It then dynamically displays certain images based on what value was selected and then sent. I hope that makes more sense.
 
so then this should suffice:

Code:
var e_select = document.getElementById("hotel");
var hotel = e_select.options[e_select.selectedIndex].value;
var strURL = "border2.asp?page_id=51&h=" + hotel;
    
window.location = strURL;

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
does your select list actually have an id attribute of "hotel"?

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
This is the way I have the select list named

<select size="1" name="hotel" onChange="refreshPage()">

Is that correct? Also on a side note, is there a way to maybe pass the selected value to the function? i.e. something like:

onChange="refreshPage(hotel.value)"

Just a thought.
 
jemminger said:
does your select list actually have an id attribute of "hotel"?

-jeff
cLFlaVA said:
attribute jeff? whatchu talkin' bout?

I think he's referring to this:
Code:
var e_select = [COLOR=blue]document.getElementById("[COLOR=red]hotel[/color]")[/color];
trojan800 said:
There is a dropdown box called 'hotel'

Your dropdown box should have something like:
Code:
<select name="hotel" [COLOR=red]id="hotel"[/color]>
  ...
</select>


---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
SWEET!!!! Marcus you get a star. The id was the missing piece. Thanks everyone for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top