PDA

View Full Version : JavaScript - HELP?



lolwut
29-12-2007, 07:14 PM
Right well, what I want is like a thing where they select the site from a drop down form box, and it takes them there.
Here's my code:

<html><head>
<script type="javascript">
var to = "";
function goTo(to)
{
window.location=to;
}
</script>
</head>
<body>
Where would you like to go today?: <select>
<option onClick="goTo('http://google.co.uk');">Google UK</option>
<option onClick="goTo('http://google.fr');">Google France</option>
</select>
</body>
</html>Any help appreciated.

EDIT: Nevermind, I've got it. :)

Moved by Agesilaus (Forum Moderator) from Design & Development: Please post in the correct forum next time. :)

php.net
29-12-2007, 08:17 PM
<form name="form1" id="form1">
<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
<option value="#">Text in here</option>
<option value="#">Text in here</option>
<option value="#">Text in here</option>
</select>
<input type="button" name="Button1" value="Go" onclick="MM_jumpMenuGo('menu1','parent',0)" />
</form>



<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
//-->
</script>

Is another way to do it, even though it's longer and messier. :p

MrCraig
30-12-2007, 09:21 PM
Doesnt dreamweaver produce the above code :S?

Want to hide these adverts? Register an account for free!