...

View Full Version : Onchange Event in Option Value to open new window



holty
04-23-2004, 12:48 PM
Hi All :D

I want a dropdown box with links in, some links will open in the same window and others I want to open in a new window.

I have found some code to follow for opening in the same window, but as some of my links need to open in a new window I can't seem to get it to work...

Here is my code (well not mine really!)



<SCRIPT LANGUAGE="javascript">
<!--
function gotoLink() {

// Get the currently selected item from the menu

goingTo = document.quickMenu.link.options[document.quickMenu.link.selectedIndex].value;

// If the currently selected item is not valid, do nothing. Otherwise,
// redirect the browser to the newly selected page.

if (goingTo == "")
{ return; }
else
{ self.location = goingTo; }

}
// -->
</SCRIPT>

</head>
<body>

<FORM NAME="quickMenu">
<LABEL>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
</label>
<SELECT NAME="link" ONCHANGE="gotoLink()">
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/" target="_blank">Alabamatttt</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/California/">California</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</OPTION>
<OPTION VALUE="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</OPTION>
</SELECT>
</FORM>
</body>


Hope you can help - as you can see the target="_blank" doesn't work....

mpjbrennan
04-23-2004, 01:06 PM
In the example below Alabama opens in the main window, Alaska opens in a new window.

patrick


<html>
<head>
<script type="text/javascript">
<!--
function newWin(x){
window.open(x, "", "height=400px, width=500px")
}
// -->
</script>

</head>
<body>

<form name="quickMenu">
<label>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
</label>
<select name="link">
<option value="http://dir.yahoo.com/Regional/U_S__States/Alabama/" onclick="self.location=this.value">Alabama</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Alaska/" onclick="newWin(this.value)">Alaska</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/California/">California</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</option>
</select>
</form>
</body>
</html>

holty
04-23-2004, 01:56 PM
Hi - thanks for the reply - but I can't get it to work....


I've also tried to change the onclick to onchange and its still won't work - any ideas?

mpjbrennan
04-23-2004, 02:53 PM
Whoops! - you're right , it only works in Mozilla. I should have tested it in IE before posting.

Need to think.....

patrick

holty
04-23-2004, 03:03 PM
Cheers - look forward to your response :thumbsup:

mpjbrennan
04-23-2004, 06:57 PM
Hi Holty,

Try this version - it checks out in Mozilla and IE6. If you want a new window give the relevant option the title newWin, otherwise give it the title "".

patrick



<html>
<head>
<script type="text/javascript">
<!--
function goLink(x, y){
if(!x){return false}
y == "newWin" ? window.open(x, "", "height=400px, width=500px") : self.location = x
document.getElementById("select1").selectedIndex = 0
}
// -->
</script>

</head>
<body>

<form name="quickMenu">
<label>Get information from <A HREF="http://www.yahoo.com">Yahoo</A> about one of the states:
</label>
<select id="select1" name="link" onchange="goLink(this.options[this.options.selectedIndex].value,this.options[this.options.selectedIndex].title )">
<option title="" value="" selected="selected">Select</option>
<option title="" value="http://dir.yahoo.com/Regional/U_S__States/Alabama/">Alabama</option>
<option title="newWin" value="http://dir.yahoo.com/Regional/U_S__States/Alaska/">Alaska</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Arizona/">Arizona</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Arkansas/">Arkansas</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/California/">California</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Colorado/">Colorado</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Connecticut/">Connecticut</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Delaware/">Delaware</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Florida/">Florida</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Georgia/">Georgia</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Hawaii/">Hawaii</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Idaho/">Idaho</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Illinois/">Illinois</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Indiana/">Indiana</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Iowa/">Iowa</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Kansas/">Kansas</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Kentucky/">Kentucky</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Louisiana/">Louisiana</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Maine/">Maine</option>
<option value="http://dir.yahoo.com/Regional/U_S__States/Maryland/">Maryland</option>
</select>
</form>
</body>
</html>


patrick



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum