View Full Version : Form option specifying new window
pinkotoad
07-17-2002, 12:12 AM
I have a simple select menu in a table:
<table>
<td>
<select name="box_1" size="1">
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
<td>
<a href="moreinfo.htm">More info</a>
</td>
</table>
What I want is when you click on "More info" is for a new window to open and have a different page open if 2 was selected instead of 1.
I fumbled around a bit, got a window to open, but have absolutely no idea how to go about letting the option specify which page to open.
Thanks
Spookster
07-17-2002, 12:17 AM
http://www.javascriptkit.com/script/script2/combocheck.shtml
pinkotoad
07-17-2002, 03:34 AM
The only problem there is that I am using the value tag for something else.
requestcode
07-17-2002, 04:01 AM
You could do something like this:
<html>
<head>
<title>Test</title>
<SCRIPT LANGUAGE="JavaScript">
var mylinks=new Array()
mylinks[0]="page1.html"
mylinks[1]="page2.html"
function openwin()
{
linkid=mylinks[document.myform.box_1.selectedIndex]
NewWin=window.open(linkid,"win")
}
</SCRIPT>
</head>
<body>
<FORM NAME="myform">
<select name="box_1" size="1">
<option value="1" selected>1</option>
<option value="2">2</option>
</select>
</FORM>
<A HREF="javascript:openwin()">More Info</A>
</body>
</html>
Set up an array with the links you want to use and then use the selectedIndex to grab the link from the array.
premshree
07-17-2002, 01:21 PM
Here's the page with the script :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Swap Target</title>
<script language="JavaScript">
// Swap Target Function
function swapTarget()
{
if(document.all.form1.box_1.selectedIndex==0)
{
document.all.moreinfo.setAttribute("target","_self")
}
else
{
document.all.moreinfo.setAttribute("target","_blank")
}
}
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="form1">
<table>
<tr>
<td>
<select name="box_1" size="1" onChange="swapTarget()">
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
<td>
<a href="moreinfo.htm" id="moreinfo" target="">More info</a>
</td>
</tr>
</table>
</form>
</body>
</html>
:thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.