HTMLweasel Posted March 29, 2006 Share Posted March 29, 2006 Hi thereAnyone know how to link a web page to another page based on a certain condition.So say for username and passowrd someone clicks on the submit button and if the conditions are met then the page closes and opens a new page. Any ideas?Thanks Link to comment Share on other sites More sharing options...
Rachit Shah Posted March 29, 2006 Share Posted March 29, 2006 (edited) Check this. Just click submit. Based on authentication details, it will redirect to google. Key is document.location='http://www.google.com'; <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication() {var UserName=document.getElementsByName('UserName').item(0).value;var Password=document.getElementsByName('Password').item(0).value;if(UserName == 'rachit' && Password == 'password1'){alert('Successfully Authenticated - Redirecting to google.com');document.location='http://www.google.com';}else{alert('Failed to Authenticate - Put the code for error msg here');}}//--></script> <body><form method="POST" action="--WEBBOT-SELF--"><!--webbot bot="SaveResults" U-File="C:\Documents and Settings\161470\Desktop\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><table border="0" width="50%" id="table1" align=center><tr><td>User Name</td><td><input type="text" name="UserName" size="20" value='rachit'></td></tr><tr><td>Password</td><td><input type="text" name="Password" size="20" value='password1'></td></tr></table><p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form><table border="0" width="50%" id="table2" align=center><tr><td>Another input with same name</td><td><input type="text" name="UserName" size="20"></td></tr></table></body></html> Edited March 29, 2006 by Jonas Link to comment Share on other sites More sharing options...
HTMLweasel Posted March 29, 2006 Author Share Posted March 29, 2006 Flip thanks lots man hehe you dominate at this stuff:) Link to comment Share on other sites More sharing options...
HTMLweasel Posted March 29, 2006 Author Share Posted March 29, 2006 Hey man I tried the code but I left out this stuff<form method="POST" action="--WEBBOT-SELF--"><!--webbot bot="SaveResults" U-File="C:\Documents and Settings\161470\Desktop\_private\form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->I just had <form>And obviously it doesn't work then. What does this stuff do and is it all necessary?Thanks Link to comment Share on other sites More sharing options...
Rachit Shah Posted March 29, 2006 Share Posted March 29, 2006 (edited) Thats not necesssary at all. Its working. Check this. I think Its information for website downloaders like 'website copier' which downloads sites automatically. <html><head><meta http-equiv="Content-Language" content="en-us"></head><script type="text/javascript"><!--function ValidateAuthentication() {var UserName=document.getElementsByName('UserName').item(0).value;var Password=document.getElementsByName('Password').item(0).value;if(UserName == 'rachit' && Password == 'password1'){alert('Successfully Authenticated - Redirecting to google.com');document.location='http://www.google.com';}else{alert('Failed to Authenticate - Put the code for error msg here');}}//--></script> <body><form ><table border="0" width="50%" id="table1" align=center><tr><td>User Name</td><td><input type="text" name="UserName" size="20" value='rachit'></td></tr><tr><td>Password</td><td><input type="text" name="Password" size="20" value='password1'></td></tr></table><p align="center"><input type="button" value="Submit" name="B1" onclick="ValidateAuthentication()"><input type="reset" value="Reset" name="B2"></p></form><table border="0" width="50%" id="table2" align=center><tr><td>Another input with same name</td><td><input type="text" name="UserName" size="20"></td></tr></table></body></html> Edited March 29, 2006 by Jonas Link to comment Share on other sites More sharing options...
HTMLweasel Posted March 29, 2006 Author Share Posted March 29, 2006 (edited) Hey man sorry this is my code and I can't get it to work. Have tried anything. <html><head><title>Military Web Portal</title></head><script type="text/javascript">var username1 = "ryan"var password1 = "ryanpassword"var username2 = "john"var password2 = "johnpassword"var username3 = "tim"var password3 = "timpassword"function accessValidation(){var tempName=document.getElementsByName('txtUsername').item(0).value;var tempPassword = document.getElementsByName('txtPassword').item(0).value;if(tempName == username1 && tempPassword == password1){document.location='http://www.google.com';}else if(tempName == username2 && tempPassword == password2){alert("User 2 access");}else if(tempName == username3 && tempPassword == password3){alert("User 3 access");}else {alert("Please enter the correct username and password");} document.location='http://www.google.com';}</script><body><table border="1" width="100%" id="table1" height="469"> <tr> <td height="110"> <img border="0" src="logo.png" width="892" height="105"></td> </tr> <tr> <td align="left" valign="top"> <form> <p>Username: <input type="text" name="txtUsername" size="20"></p> <p>Password: <input type="password" name="txtPassword" size="20"></p> <p><input type="submit" value="Login" name="B1" onclick = "accessValidation()"> <input type="reset" value="Reset" name="B2"></p> </form> </td> </tr></table></body></html> For some reason the same page is loaded. Any ideas?Please thanks Edited March 29, 2006 by Jonas Link to comment Share on other sites More sharing options...
Rachit Shah Posted March 29, 2006 Share Posted March 29, 2006 (edited) Plz remove submit button, otherwise it will try to submit the form to the url specified in action attribute.I have replaced it with button <html><head><title>Military Web Portal</title></head><script type="text/javascript">var username1 = "ryan"var password1 = "ryanpassword"var username2 = "john"var password2 = "johnpassword"var username3 = "tim"var password3 = "timpassword"function accessValidation(){var tempName=document.getElementsByName('txtUsername').item(0).value;var tempPassword = document.getElementsByName('txtPassword').item(0).value;if(tempName == username1 && tempPassword == password1){document.location='http://www.google.com';}else if(tempName == username2 && tempPassword == password2){alert("User 2 access");}else if(tempName == username3 && tempPassword == password3){alert("User 3 access");}else {alert("Please enter the correct username and password");}document.location='http://www.google.com';}</script><body><table border="1" width="100%" id="table1" height="469"><tr><td height="110"><img border="0" src="logo.png" width="892" height="105"></td></tr><tr><td align="left" valign="top"><form><p>Username: <input type="text" name="txtUsername" size="20"></p><p>Password: <input type="password" name="txtPassword" size="20"></p><p>[b][color="blue"]<input type="button" value="Login" name="B1" onclick = "accessValidation()">[/color][/b]<input type="reset" value="Reset" name="B2"></p></form></td></tr></table></body></html> Edited March 29, 2006 by Jonas Link to comment Share on other sites More sharing options...
Rachit Shah Posted March 29, 2006 Share Posted March 29, 2006 plz remove this document.location otherwise it will redirect to google in case of authentication failure even. }document.location='http://www.google.com';}</script> Link to comment Share on other sites More sharing options...
HTMLweasel Posted March 29, 2006 Author Share Posted March 29, 2006 Thanks so much it finally worksJust wanted to check - so if I put in an action in my button<input type="button" value="Login" name="B1" onclick = "accessValidation()">and type was submit it would link that to the action?Thanks again:) Link to comment Share on other sites More sharing options...
scott100 Posted March 29, 2006 Share Posted March 29, 2006 Thanks so much it finally worksJust wanted to check - so if I put in an action in my button<input type="button" value="Login" name="B1" onclick = "accessValidation()">and type was submit it would link that to the action?Thanks again:)<{POST_SNAPBACK}> With a submit button you can stop it submitting to an action.<form action="google.com" onsubmit="return accessValidation()">in the function accessValidation() you will return either true or false depending on if the login is correct. Link to comment Share on other sites More sharing options...
Jonas Posted March 29, 2006 Share Posted March 29, 2006 Lifeseries' topic can now be found in this thread here:http://w3schools.invisionzone.com/index.php?showtopic=3512If you see thread hijacking (bringing a thread off-topic, asking for help on own topic instead), please give us a report. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now