PDA

View Full Version : simple form help needed


lee.unsworth
02-21-2009, 10:00 AM
Hi i have a simple form command i need help with. the code i have so far is

<form id="form1" name="form1" method="post" action="" >
<label>Reference Number </label>
<input name="textfield" type="text" />
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>

what i want to be able to do is,
if the user enters in say, 12345 it will take them to page1.html
but if the user enteres 67890 it will take them to page2.html

davidj
02-21-2009, 11:46 AM
you need to do this in either javascript or a serverside language like php

in my example if you key 1 you will be redirected and 2 and 3 etc


<script>

function getFormVal(){

f = getElementById('textfield');

u = document.location;

switch(f.value){

case'1': u.href="page1.htm"; break;
case'2': u.href="page2.htm"; break;
case'3': u.href="page3.htm"; break;

}

return false;

}

</script>


///////////////////////////////////////////


<form id="form1" name="form1" method="post" action="" >
<label>Reference Number </label>
<input name="textfield" type="text" />
<label>
<input type="button" name="Submit" value="Submit" onclick="getFormVal()"/>
</label>
</form>

lee.unsworth
02-21-2009, 02:27 PM
sorry to sound dumb but im quite new to all this.

do i need to add the script to my html page and save as .asp javascript. if so where abouts on the page do i add it.

or are these going to be 2 separate documents

thanks for your help.

davidj
02-21-2009, 02:48 PM
you need to add the script inside the head tags

then in my form example you can see where i am calling the function

davidj
02-21-2009, 02:51 PM
if this is still beyond your skillset then i advise you study some tutorials and learn about javascript programming