Forum Moderators: open

Message Too Old, No Replies

redirecting form selections

         

joshenry

9:40 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Hi, newbie here.

I use the form below to create a drop-down menu for navigation.

Is there any way to have the selection open in a new window. I've found how to redirect the selections for the whole form, but is there any way to just redirect one or two individual selections ...say, "Page 4" and "Page 5, to open in a new window while the remaining selections open in the parent window. Any and all suggestions would be appreciated.

Joseph

<FORM> ...OR GO TO
<SELECT NAME="URL" onChange="if(options[selectedIndex].value)window.location.href=(options[selectedIndex].value)">
<OPTION SELECTED VALUE="">Another Page: </OPTION>
<OPTION VALUE="Page1.html">Page1</OPTION>
<OPTION VALUE="Page2.html">Page2</OPTION>
<OPTION VALUE="Page3.html">Page3</OPTION>
<OPTION VALUE="Page4.html">Page4</OPTION>
<OPTION VALUE="Page5.html">Page5</OPTION>
</SELECT>
</FORM>

CaseyRyan

10:01 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



I would add a delimitor into the value, parse it out and go where it tells you. I've written up and example below.


<script language="javascript">
function goToURL(oSelect){
var _value = oSelect.options[this.selectedIndex].value;
if (_value!= "") {
var _target = _value.split("¦")[0];
var _url = _value.split("¦")[1];
if (_target == "new"){
window.open(_url);
}else{
window.location.href=_url;
}
}
}
</script>
<FORM> ...OR GO TO
<SELECT NAME="URL" onChange="goToURL(this)">
<OPTION SELECTED VALUE="">Another Page: </OPTION>
<OPTION VALUE="new¦Page1.html">Page1</OPTION>
<OPTION VALUE="new¦Page2.html">Page2</OPTION>
<OPTION VALUE="new¦Page3.html">Page3</OPTION>
<OPTION VALUE="self¦Page4.html">Page4</OPTION>
<OPTION VALUE="self¦Page5.html">Page5</OPTION>
</SELECT>
</FORM>

-=casey=-

joshenry

5:43 am on Mar 11, 2005 (gmt 0)

10+ Year Member



Casey,

Thanks for the reply. I modified my form and added to the page the javascript you supplied, but nothing happened. Not only did it not accomplish what I'd hoped for (opening the target in a new window), but nothing happens at all.

I don't know enough about javascripting to even begin to "analyze" this. I can only say, thanks for the attempt.

Joseph

Bernard Marx

9:15 am on Mar 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Casey's idea makes sense - although I'd be tempted to use custom attributes here (validation - pah!).

There are two things wrong with the code:

1. A quick change needed

var _value = oSelect.options[this.selectedIndex].value;
//to//
var _value = oSelect.options[oSelect.selectedIndex].value;

2. This one isn't casey's fault.

WebmasterWorld changes the pipe char ¦ into what yop see - a broken pipe.
Change all broken pipes in the code into unbroken pipes.
(or use a different delimiter entirely).

CaseyRyan

3:05 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



Thanks Mr. Marx for siting that error. With that fix and replacing the broken pipes with actual pipes, the code should work.

-=casey=-

joshenry

4:36 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



I'd been searching a very, very long time for a solution to this. Thanx guys!