...

View Full Version : How can I redirect to a new page based on a text box value?



Trainer Eddie
09-28-2005, 10:30 AM
I'm creating an emulator of a GUI for my training department. Without using a drop-down menu, is there a way to have a user type in a 10 digit string, submit, then be redirected to a page in a new folder?
It's so I can set up fictitious accounts for trainees to work in, and each number (new folder) will represent an account with it's own unique situations. I don't want to use a drop-down because it doesn't simulate the live environment.
Here's the code for the text entry box in the live GUI:
<input type="text" name="mdn" maxlength="10" size="15" value="" onfocus="javascript:getIt(this)">
I need to have the 10 digits (ex: 5551234567) as entered into the MDN field point to a file named 5551234567.htm and change the existing window to that file.
Should this maybe be an if/else script where I can define all the links by file name? I'll only be using around 10 files, so defining them all wouldn't be a hassle.
Thanks all.

shyam
09-28-2005, 01:05 PM
setting the onfocus handler which will fire even before the user has a chance to enter his/her id isn't a good idea. anyway here's how u can redirect the page


function doRedirect() {
var mdn = document.myForm["mdn"].value;
if ( mdn == "..." ) {
window.location.href = "a.htm";
} else if ( mdn == "..." ) {
}..
}

Trainer Eddie
09-28-2005, 07:06 PM
Thanks, I'll bring it to work today and see how it goes. I can only do about 20 things with Javascript, so hopefully this will make it 21.

Trainer Eddie
09-29-2005, 11:25 AM
OK, now you'll see how little I understand about Javascript. Here's the whole page:

<html>
<head>
<title> SP emulator </title>
<script language="javascript" type="text/javascript">
function doRedirect() {
var mdn = document.myForm["mdn"].value;
if ( mdn == "9185551234" ) {
window.location.href = "9185551234.htm";
} else if ( mdn == "9185559876" ) {
window.location.href = "9185551234.htm";
}..
}
</script>
</head>

<body>
<form>
<table>
<tr align="left">
<td>MDN</td>
<td><input type="text" name="mdn" maxlength="10" size="15"></td>
<td><form action="#">
<input type="button" value="submit" onclick="doRedirect()">
</form></td>
</tr>
</table>
</form>
</body>
</html>
I hope you didn't crack a rib laughing. I'm lost regarding what needs to be replaced with an name that I define versus what is standard code. For instance, does "window.location.href" remain unchanged or do I need to change "location" to a specific path?
For simplicity sake let's say the main directory in at C:\emulator and the file that replaces the current window is called 9185551234.htm and is in the same directory. And if it isn't being too much of a pain, I was trying to add a button that would execute the script the same as hitting the enter key.
Thanks for the help, all, it means a lot to me.

shyam
09-29-2005, 12:23 PM
<html>
<head>
<title> SP emulator </title>
<script language="javascript" type="text/javascript">
function doRedirect() {
var mdn = document.myForm["mdn"].value;
if ( mdn == "9185551234" ) {
window.location.href = "9185551234.htm";
} else if ( mdn == "9185559876" ) {
window.location.href = "9185551234.htm";
}
}
</script>
</head>

<body>
<form name="myForm">
<table>
<tr align="left">
<td>MDN</td>
<td><input type="text" name="mdn" maxlength="10" size="15"></td>
<td><form action="#">
<input type="button" value="submit" onclick="doRedirect()">
</form></td>
</tr>
</table>
</form>
</body>
</html>

Trainer Eddie
09-29-2005, 06:35 PM
Thank you Shyam, not only will this accomplish my purpose for work, but now that I have a script I can relate to it will be easier to tie together the loose ends of what I didn't understand.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum