Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect page from list choice!

Status
Not open for further replies.

Sitehelp

Technical User
Feb 4, 2004
142
GB
I am not too good with javascript. How do I get the pages to come up if a user selects a particular list item. Each item has a different address. For example if the user selects "Personnel Information" then they will be directed to " My code for the list is:

<select name=&quot;select&quot; size=&quot;1&quot;>
<option value=&quot;Personnel Information&quot;>Personnel Information</option>
<option value=&quot;Hardware Information&quot;>Hardware Information</option>
<option value=&quot;Software Information&quot;>Software Information</option>
<option value=&quot;Licences you hold&quot;>Licences you hold</option>
<option value=&quot;Password/Username&quot;>Password/Username</option>
</select>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</p>
</form>

I just want to change it so it can redirect to each page, probably using IF statements I guess. Cheers for the help all!
 
change the VALUE attribute to be the filename that you want them to go to then you can use :

<select name=&quot;selectList&quot; size=&quot;1&quot; onChange=&quot;document.location=document.myForm.selectList.value&quot;>
 
so kinda like:

<select name=&quot;select&quot; size=&quot;1&quot;>
<option value=&quot; Information</option>
etc etc... for the list

Then........ (how do I layout the next bit please????):

<select name=&quot;select&quot; size=&quot;1&quot; onChange=&quot;document.location=document.myForm.selectList.value&quot;>

Thanks!
 
Not sure if you want to use a button, If so just call the function onSubmit. Hope this helps.
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd&quot;>;[/URL]
<html>
<head>
<title>Untitled Document</title>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function linkTo(targ,selObj){
  eval(targ+&quot;.location='&quot;+selObj.options[selObj.selectedIndex].value+&quot;'&quot;);

}
//-->
</script>
</head>

<body>
<form name=&quot;form1&quot;>
  <select name=&quot;drop-down menu&quot; onChange=&quot;linkTo('parent',this)&quot;>
    <option value=&quot;one.html&quot; selected>one</option>
    <option value=&quot;two.html&quot;>two</option>
    <option value=&quot;three.html&quot;>three</option>
  </select>
</form>
</body>
</html>

Glen
 
Thanks for the comments glenmac ;-)

For ease of management it may be worth moving the code into a function and then calling the function from the ONCHANGE. This makes it easier to manage and potentially reusable if you build the function right, such as :

<html>
<head>
<script language=&quot;javascript&quot;>
function changeURL(whichFormObj)
{
// assign the value of the form field to a variable
var newURL=whichFormObj.value;

// change the URL
document.location=newURL;
}
</script>
</head>
<body>
<form name=&quot;myForm&quot;>
<select name=&quot;myURL&quot; onchange=&quot;changeURL(this)&quot;>
<option value=&quot; Home Page</option>
<option value=&quot; another</option>
</select>
</form>
</body>
</html>
 
HMM, well ggriffit I don't see a lot of difference between your function and mine, they both work . I was hoping to be able to get the function to work using onsubmit for the form object as a button on his form but I gave up. (got tired)

Glen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top