PDA

View Full Version : Resolved Dropdown list with different target locations.



Sartavius
10-25-2011, 10:33 PM
Okay Javascript Masters, here's one for you! Lets say I want something like this:


<FORM NAME="URLlist">
<SELECT NAME="droplist">
<OPTION SELECTED="SELECTED" VALUE=" ">Select a Destination!</OPTION>
<OPTION VALUE="http://www.yoururl.com">Your Discription</OPTION>
<OPTION VALUE="http://www.yoururl1.com">Your Discription1</OPTION>
<OPTION VALUE="http://www.yoururl2com">Your Discription2</OPTION>
</SELECT><INPUT TYPE="BUTTON" VALUE="Go!" ONCLICK="GotoURL(this.form)">
<SCRIPT LANGUAGE="JavaScript">
<!--
function GotoURL(dl) {
// FRAMES - To open a selection in a document that uses frames
// change top.location.href to parent.putyourframenamehere.location.href
top.location.href = dl.droplist.options[dl.droplist.selectedIndex].value;
}
// -->
</SCRIPT>
</FORM>

Except I want the different values to open in different locations. Say a couple of them should open in the parent (of a frameset), some should open in a new window and so on.

Is this possible with the above code or am I dreaming?

jscheuer1
10-26-2011, 02:48 AM
After a fashion, yes.

Make the values comma delimited and parse the values into an open method, like:


<form name="URLlist">
<select name="droplist">
<option selected="selected" value=" ">Select a Destination!</option>
<option value="http://www.yoururl.com,_new">Your Discription</option>
<option value="http://www.yoururl1.com,_top">Your Discription1</option>
<option value="http://www.yoururl2com,yourframenamehere">Your Discription2</option>
</select><input type="button" value="go!" onclick="GotoURL(this.form)">
<script type="text/javascript">
function GotoURL(dl) {
var val = dl.droplist.value.split(',');
open(val[0], val[1]);
}
</script>
</form>

Sartavius
10-26-2011, 03:34 AM
Once again, your javascript omnipotence reigns supreme! :D

Seriously - thanks a million!