...

View Full Version : Opening Items from a Dropdown List in a New Window



dougcollins02
12-08-2011, 04:52 PM
I haven't been able to find anything about this on here or clear direction on the net, so I'm hoping y'all can help me out.

I have a dropdown list that I use to navigate pages on an external website. Currently, my dropdown list will open a new page in my current window. I want to be able to open the page in a new window.

I'm sure it's a simple fix, but being somewhat of a noob to Javascript I can't figure out how to solve it.

Here's what I have for the navigation dropdown:


<FORM
ACTION="../cgi-bin/redirect.pl"
METHOD=POST onSubmit="return dropdown(this.gourl)">
<SELECT NAME="gourl">

<OPTION VALUE="">Make Your Selection
<OPTION VALUE="http://url1.html>Choice 1
<OPTION VALUE="http://url2.html>Choice 2
<OPTION VALUE="http://url3.html">Choice 3

</SELECT>

<INPUT TYPE=SUBMIT VALUE="Go">
</FORM>

And here's what I have in the header:


<SCRIPT TYPE="text/javascript">
<!--
function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(myVal)
{
if(mySel.form.target)myWin = parent[mySel.form.target];
else myWin = window;
if (! myWin) return true;
myWin.location = myVal;
}
return false;
}
//-->
</SCRIPT>

Any ideas?

xelawho
12-08-2011, 06:52 PM
I think window.open() is what you are looking for, although your if statements have me somewhat confused:



<html>
<head>
<title></title>
</head>
<body>
<FORM
ACTION="../cgi-bin/redirect.pl"
METHOD=POST onSubmit="return dropdown(this.gourl)">
<SELECT NAME="gourl">

<OPTION VALUE="">Make Your Selection</OPTION>
<OPTION VALUE="http://url1.html">Choice 1</OPTION>
<OPTION VALUE="http://url2.html">Choice 2</OPTION>
<OPTION VALUE="http://url3.html">Choice 3</OPTION>

</SELECT>

<INPUT TYPE=SUBMIT VALUE="Go">
</FORM>
<script type="text/javascript">

function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(myVal)
{
if(mySel.form.target)myWin = parent[mySel.form.target];
else myWin = window.open();
if (! myWin) return true;
myWin.location = myVal;
}
return false;
}
</script>
</body>
</html>

dougcollins02
12-08-2011, 08:22 PM
Thanks for the help! It's working splendidly. I really appreciate you taking the time to give me a hand.

I know my "if" statements need some work. I feel good for someone just learning Javascript, but know I have a long ways to go.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum