mtber Posted June 30, 2009 Report Share Posted June 30, 2009 I am trying to use javascript to call an HTML file depending on a password entered by a user. when i click on the submit button the page does nothing and i get no errors not sure what i am doing wrong. any help is appreciated. <html><head><title>Title</title><link rel="stylesheet" language="text/css" href="index.css"/> <script type="text/javascript">function runscript(){ if(document.myForm.password.value == 'password') { window.document.location.href = <'index.htm'>; }}</script> </head><body><center><form name="myForm" action=""><fieldset size="100px"><legend>Run Script</legend><table border="1" cellspacing="0" cellpadding="2"><tr><td class="options" align="right" valign="middle"><form><font class="options"><b>User Name:</b></font></td><td align="center" valign="middle"><input type="text" size="40"><tr><td align="right" valign="middle"><font class="password"><b>Password:</b></font></td><td align="center" valign="middle"><input type="password" name="password" value="password" size="40"></td></tr><tr><td align="center" valign="middle" colspan="2"><input type="submit" value="submit" name="submit" onclick="runscript()"><input type="reset"></td></tr></form></td></tr></table></form></center></body></html> Link to comment Share on other sites More sharing options...
Ingolme Posted June 30, 2009 Report Share Posted June 30, 2009 Password protecting something with Javascript is completely pointless because people can view the source code.Problems in your code: window.document.location.href = <'index.htm'>; < and > are operators and the way you're using them here does not make sense."location" is a child of the window object, not the document object. <link rel="stylesheet" language="text/css" href="index.css"/> There is no attribute language for the <link> element. <input type="submit" value="submit" name="submit" onclick="runscript()"> You are not handling the submit event, therefore when you click the submit button the page is going to reload. 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