View Full Version : Form link

05-21-2007, 10:40 AM
Is there anyway that i can create a form, where depending on what the viewer types depends on what webpage they go to. I have a page where i want it to go.
For example. The viewer is on the home page (0), on that page there is a form. If they type in 1 it will go to page (1) or if they type in 2 it will go to (2), but if they type in a page that does not exist they get a custom error.

I'm not even sure this is the right section to put it in.:confused:

05-22-2007, 03:45 PM
From your description it is not clear whether the user is required to click a submit button or not after selecting the number.

In any case, either way, to get what you want you would need either server-side scripting (e.g. php) or JavaScript.

05-23-2007, 09:37 AM
Well i want the users to click submit, and i would rather use javascript, does anyone know what to do with it

05-23-2007, 10:22 AM
Having a navigation system that relies solely on javascript is very bad from an accessibility point of view. Not everyone has javascript enabled. I don't have javascript enabled by default. Here is how you do it with javascript.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function goTo()

var el = document.getElementById('pagenum').options[document.getElementById('pagenum').options.selectedIndex].value;
if(el == 'none')
alert('You have not chosen a page number.');
window.location = el;
return false;
<form action="#" method="post" onsubmit="return goTo(this.pagenum.value)">
<select name="pagenum" id="pagenum">
<option value="none">Choose a page</option>
<option value="page1.html">Page 1</option>
<option value="page2.html">Page 2</option>
<option value="page3.html">Page 3</option>
<option value="page4.html">Page 4</option>
<input type="submit" value="Go">
I think the select menu is a little more user friendly than an input box.

05-23-2007, 10:29 AM
thanks alot mate. that seems great, but just out of interest what would need to be changed to make it an input box