Forum Moderators: open

Message Too Old, No Replies

Form Redirect Help! Have never coded Java before.

Form to redirect to a page depending on value entered in text field.

         

nathanpinard

6:31 am on Jun 1, 2004 (gmt 0)

10+ Year Member



Hello All,

I don't know Java yet, and I had planned on purchasing several books about various programming but I need help right away on this one.

I need a script to be written, but also explained for me so I can reference it in the future. This shouldn't be long at all.

The form will consist of one text field, that is all.

There will be 6 different values that can be entered in this field. Let just call them:

1
2
3
4
5
6

Eventually these will be passwords that people can enter. Depending on the password, they will be redirected to a specific page, that is all.

If they do not enter the right one, then they will be redirected to an error page.

This is for a price list based on a promotion code they enter.

Please help if you can, thank you.

Nathan

Bernard Marx

9:24 am on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Client-side Javascript isn't really suited to passwords. This can be done in javascript, but the passwords will be visible in the source code. You couls use some kind of 'obfuscation' technique, but nothing will be logically hidden. Really, you need something server-side (PHP, ASP et al).

If you aren't too bothered about people cheating, it wouldn't b hard to do something in Javascript that jumbles the information, so it's at least visibly hidden. Interested?

nathanpinard

3:02 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Yes. That would work. Thanks.

PHP or ASP can be something I will later deal with, but now I just need a temp solution.

Nathan

Bernard Marx

6:39 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's the simplest one. This requires the passwords to be the actual filenames of the pages ( less the extension). This one does hide the password for this reason, but if they put in an incorrect password, the error page they'll get is the standard 404.

<html>
<head>
<title>test pass</title>
<script>
function checkPass()
{
window.location.href = document.getElementById("pass").value
}
</script>

</head>

<body>

<input id="pass" type="password" value = ""><br>
<button onclick="checkPass()">go</button><br>

</body>
</html>

nathanpinard

7:30 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Thankyou,

I've entered the code.

So you coded it so if I enter in the code "1234", it will go to 1234.htm?

I've entered the code in for the correct page, however I get a 404 no matter what I enter. Does it look for the file in the same directory the password page is in, or is it looking for a file in the root folder?

nathan

MichaelBluejay

7:44 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should look for the file in the same directory the password page is on.

The code that Bernard posted doesn't automatically add the ".html", so if a user enters "1234" then JavaScript will try to load a file named "1234", not a file named "1234.html". To get the ".html" added then change your "window.location..." line to this:

window.location.href = document.getElementById("pass").value + ".html";

Bernard Marx

7:52 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Too right. Sorry, I rushed off to eat without checking.

This should do it.
Change the path to get to a different directory
and / or change the extension:

<script> 
function checkPass()
{
var path = "./"
window.location.href = path + document.getElementById("pass").value + ".htm"
}
</script>