Help - Search - Members - Calendar
Full Version: Drop Down Menu problem
HTMLHelp Forums > Programming > Client-side Scripting
jarar
I'm trying to setup a drop down menu that when submitted it takes user to a new url, but within the same window. See my current code below. Note: This code takes users to the url, but it open up a new window. I want it to go to the url within the same window.

-------
<script>function goToNewPage(dropdownlist) { var url = dropdownlist.options(dropdownlist.selectedIndex).value; if (url != "") { window.open(url); } }</script>
-------

<form style="margin-bottom:0;" name="dropdown" >
<select name="list" accesskey="E">
<option selected="selected">Please select a state</option>
<option value="sorry.html">Alabama</option>
<option value="sorry.html">Arizona</option>
<option value="sorry.html">Arkansas</option>
</select>
input type="image" src="images/WeShopDlvr_selectbtn2.jpg" width="38" height="39" align="left" onclick="goToNewPage(document.dropdown.list)" />

Any help would be appreciated
pandy
Because window.open() opens a new window. Use 'window.location.href = url;' .
jarar
QUOTE(pandy @ Aug 29 2009, 04:11 AM) *

Because window.open() opens a new window. Use 'window.location.href = url;' .


Hi Pandy,

I'm a newb when it comes to this and appreciate your help. I'm still doing something wrong. Here is the script. I used your suggestion, but I must have placed it incorrectly.

<script>function goToNewPage(dropdownlist) { var url = dropdownlist.options(dropdownlist.selectedIndex).value; if (url != "") { window.location.href = url; } }</script>

I'm obviously missing something.

-J

pandy
Yar, the bit in BODY is wrong. Did it really work at all before?

I found a page for you with detailed explanations. smile.gif
http://www.pageresource.com/jscript/jdropbox.htm

P.S. SCRIPT should have a 'type' attribute. It isn't crucial, but it's nice. happy.gif
http://htmlhelp.com/reference/html40/special/script.html
jarar
QUOTE(pandy @ Aug 29 2009, 04:26 PM) *

Yar, the bit in BODY is wrong. Did it really work at all before?

I found a page for you with detailed explanations. smile.gif
http://www.pageresource.com/jscript/jdropbox.htm

P.S. SCRIPT should have a 'type' attribute. It isn't crucial, but it's nice. happy.gif
http://htmlhelp.com/reference/html40/special/script.html


Thank you so much, it works great. Unfortunately, I needed a custom image for the button and it doesn't allow that, unless I modify the code. I can deal with the code provided and the default "go" button. Unless you know how to modify it to allow a custom image. I have searched and searched online and the only think I can find is to replace the ---> input type="button" name="go" WITH---> input type="image" src="image.jpg" code, but it doesn't work with the script.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.