PDA

View Full Version : New Window for OnClick Event...


delbugsdad
01-29-2003, 09:32 PM
Here's the thing...I would like to make the webpage select launch in a seperate browser window. I'm not sure how to do that at this point. I have searched the posts regarding this and since I'm new to this, I can't make a whole lot of sense of what was posted. Anyway, if someone could help me out, it would be appreciated. Code below...


<form name="newform" >
<select name="newselect" size="1" align="left" style="background-color:#ffffff" onChange="phonedesc(document.newform.newselect.selectedIndex)">
<option selected value="file:///x:/webpage.htm">This is the webpage</option>
</select>
<input type="button" value="Go"
onClick="location=document.newform.newselect.options[document.newform.newselect.selectedIndex].value"><br>

There is script below this that changes a display under the menu when each value is selected. If at all possible, I would like a new window to appear with the selected webpage. I hope this makes sense and I hope someone can help.

Thanks.

delbugsdad
(frustrated noob)

whammy
01-30-2003, 01:09 AM
<html>
<head>
<title>Open a new window with a dropdown using javascript!</title>
<script type="text/javascript">
<!--
function OpenWindow(val) {
if(val) window.open(val);
}
// -->
</script>
</head>
<body>
<form id="form1" action="javascript:void 0">
<select name="myselect" onchange="OpenWindow(this.options[this.selectedIndex].value)">
<option value="">Choose a website!</option>
<option value="http://www.google.com">Google it!</option>
<option value="http://www.yahoo.com">Yahoo!</option>
<option value="http://www.download.com">Find a cool program!</option>
</select>
</form>
</body>
</html>


Hope this helps! This is about the most concise example I can provide, which also passes a function parameter.

Probably the best way I can explain this, is the bolded part in the select dropdown is what gets passed to the function parameter "val" (the parameter name doesn't matter since it becomes a local variable which is only accessible by the function "OpenWindow()". You could name it "dog", for instance).

Whenever I try to provide a more detailed explanation, I'm liable to make it more confusing. The example above should suffice to help you figure it out on your own, though.

:)

delbugsdad
01-30-2003, 04:37 PM
Thanks for your help. With the example provided, I believe I can figure it out.

delbugsdad
not so frustrated noob