Forum Moderators: open

Message Too Old, No Replies

Open new window using a pull down menu

new window on pull downs

         

getincite

3:50 pm on Jul 15, 2003 (gmt 0)

10+ Year Member



Anyone know of a method to go to a new window using a Java Script pull down menu? The site is NOT in frames, but I need to go to a new window when the pull down optio is selected.

Thanks, steve

BlobFisk

3:58 pm on Jul 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By JavaScript pull down menu, do you mean a dHTML menu system?

In that case, you can insert a window.open into the code for the link...

getincite

2:58 am on Jul 16, 2003 (gmt 0)

10+ Year Member



No, it is not dHTML but JavaScript.

Here is the code

<SCRIPT LANGUAGE="JavaScript">
<!--
function formHandler(form){
if(form.site.options[form.site.selectedIndex].value!= "")
window.location.href = form.site.options[form.site.selectedIndex].value;
}
// -->
</SCRIPT>

And then one of the pull down items look like this
<form onSubmit="formHandler(this); return false">
<select name="site" size="1">
<option value="">Select Size to order
<option value="http://www.domainname.com"> 1 oz. $12.95
</select>
<input type="submit" value="Go!">
</form>

Any way to get this to open to a new window?
Steve

keyplyr

6:57 am on Jul 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Hi getincite, can't answer you question concerning the new window (although I think it can be done) but there are a couple things in your code that are no longer supported.

You should change: <SCRIPT LANGUAGE="JavaScript">

to the newer: <script type="text/javascript">

And remove the comments: <!-- and // -->

They once were useful in hiding JS from early browsers who did not support it, but those days have come and gone.

tedster

7:41 am on Jul 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should work if you swap out the window.location.href and use the window.open() method instead inside the formHandler(form) function. The new function would look something like this:

function formHandler(form){
newurl=form.site.options[form.site.selectedIndex].value;
if (newurl!= "")
{window.open(newurl,'new','<!--add features string here as needed-->') }
}

getincite

3:31 pm on Jul 16, 2003 (gmt 0)

10+ Year Member



Thanks keyplr and tedster,

it worked. many many thanks,
steve