Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I redirect to a new page based on a text box value?

    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.
    Last edited by Trainer Eddie; 09-28-2005 at 11:49 AM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    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

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

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, now you'll see how little I understand about Javascript. Here's the whole page:
    Code:
    <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.

  • #5
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    <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>

  • #6
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •