Click to See Complete Forum and Search --> : JavaScript onChange Question


jordanj
04-04-2003, 09:15 AM
Hello,

I'm fairly new with using the onChange event handler, and have a question. I created an online form that has a pull down options menu. What I like to do is when a user selects an item from the menu, and entirely new browser window will open up.

I currently have a script setup so when a user selects an item from the menu, it forwards them to a web page, but it uses the same browser window the form is using.

Below is the script I'm currently using.

<head>

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from older browsers

function jumpPage(newLoc) {
newPage = newLoc.options[newLoc.selectedIndex].value

if (newPage != "") {
window.location.href = newPage
}
}

// End hiding script from older browsers -->
</SCRIPT>
</head>

<body>
<form name="register" method="post" action="test.cgi">

<SELECT NAME="newLocation" onChange="jumpPage(this.form.newLocation)">

<OPTION VALUE="" SELECTED>United States
<OPTION VALUE="test.html">Other Country
</SELECT>

<NOSCRIPT>
<INPUT TYPE=SUBMIT VALUE="Go There!">
</NOSCRIPT>

</form>
</body>

Any help will be greatly appreciated. :)

Thanks,

Jeremy

gil davis
04-04-2003, 09:22 AM
This is the simplest method:if (newPage != "") {
window.open(newPage);
}For more options, see http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/open_0.asp#open_0

khalidali63
04-04-2003, 09:22 AM
Instead of

if (newPage != "") {
window.location.href = newPage
}

use new window

if (newPage != "") {
window.open(newPage,"newWin","");
}

this will open the newPage in a new window

Cheers

Khalid