PDA

View Full Version : Javascript : Auto redirection select dropdown .... weird


cinq
03-09-2005, 07:24 AM
I am trying to place this auto redirect select dropdown box on the postbits of all member.

The code:


<Script language="JavaScript">
<!-- Script courtesy of http://www.web-source.net - Your Guide to Professional Web Site Design and Development
function goto(form) { var index=form.select.selectedIndex
if (form.select.options[index].value != "0") {
location=form.select.options[index].value;}}
//-->
</SCRIPT>
<FORM NAME="form1">
<SELECT NAME="select" ONCHANGE="goto(this.form)" SIZE="1">
<OPTION VALUE="$vboptions[bburl]/index.php">Home
<OPTION VALUE="$vboptions[bburl]/usercp.php">Control Panel
</SELECT>
</FORM>

used code from here (http://www.web-source.net/javascript_redirect_box.htm)

Once there, all a user has to do is select the appropriate item in the dropdown, say "Control Panel" and it will automatically redirect to the usercp.php page.

However it doesn't seem to redirect. Anyone, any ideas why this doesn't work ? :(

Edit : hmm odd, it works on IE it seems but not on Firefox.
Is there any way around it so that it works on all browsers ?

Ok nvm...ended up using this code and it seems to work :


<SELECT name="select" ONCHANGE="window.location=(this.options[selectedIndex].value);" SIZE="1">

Colin F
03-09-2005, 02:45 PM
Alternately you could have a look at the code used for the dropdown menus in the admincp (for usergroups for example).

Jolten
03-09-2005, 03:02 PM
The script I use....


<script language="JavaScript">
<!--
function goToURL(form)
{

var myindex=form.dropdownmenu.selectedIndex
if(!myindex=="")
{
//window.location.href=form.dropdownmenu.options[myindex].value;

//This is an alternative method you can use
var Target = "_blank";
window.open(form.dropdownmenu.options[myindex].value,Target,"");
}
}
//-->
</script>


I've got the top string commented out because I wanted new windows when selected. You can uncomment it and comment out the alternative method to open links in the same window.

and the form...


<form name="dropDownForm">
<select name="dropdownmenu" size="1" onChange="goToURL(this.form)">
<option value="url">Text</option>
<option value="url">Text</option>
</select>
</form>


This works perfectly with every browser as far as I know.