naveenbj Posted January 10, 2008 Share Posted January 10, 2008 Is there is smthing wrong in this script? <script language="javascript"> function validate() if(document.form1.username.value!='jimmy') { alert("Enter correct user name."); return false; } if(document.form1.password.value!='123456') { alert("Enter correct password."); return false; } return true; } --------------------------- here wht i want is to validate username password from predefined values. I hope you can understand.. Regards, Nj Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 10, 2008 Share Posted January 10, 2008 post your full code !! Quote Link to comment Share on other sites More sharing options...
naveenbj Posted January 10, 2008 Author Share Posted January 10, 2008 here is the code <html> <head><title>admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript"> function validate() if(document.form1.username.value!='jimmy') { alert("Enter correct user name."); return false; } if(document.form1.password.value!='123456') { alert("Enter correct password."); return false; } return true; } </script> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><b><font color="#666600">Admin panel</font></b></p> <table width="34%" border="1" align="center" height="137" cellpadding="0" cellspacing="0"> <form namme="form1" method="post" onSubmit="return validate();"> <tr> <td height="62" bgcolor="#CCCCCC"><b><font color="#990000">User name :</font></b></td> <td height="62" bgcolor="#CCCCCC"> <input type="text" name="username"> </td> </tr> <tr> <td height="70" bgcolor="#CCCCCC"><b><font color="#990033">Password :</font></b></td> <td height="70" bgcolor="#CCCCCC"> <input type="password" name="password"> </td> </tr> <tr> <td height="26" bgcolor="#CCCCCC"> </td> <td height="26" bgcolor="#CCCCCC"> <input type="submit" name="Submit"> </td> </tr> </form> </table> </body> </html> Regards Nj Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted January 10, 2008 Share Posted January 10, 2008 First we need to see how you're calling the validate function. Second, you have the valid values entered directly into the Javascript, which is a terrible idea. Quote Link to comment Share on other sites More sharing options...
naveenbj Posted January 10, 2008 Author Share Posted January 10, 2008 Thanks for reply!! thn wht i hav to do k=now?? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted January 10, 2008 Share Posted January 10, 2008 <form namme="form1" Do you see what you've done there? Quote Link to comment Share on other sites More sharing options...
naveenbj Posted January 10, 2008 Author Share Posted January 10, 2008 oh sry but still its not working:( Regards Nj Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted January 10, 2008 Share Posted January 10, 2008 your code should be , you missed out a "{" for the validate function and misspelled the name of the form <html> <head><title>admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript"> function validate() { if(document.form1.username.value!='jimmy') { alert("Enter correct user name."); return false; } if(document.form1.password.value!='123456') { alert("Enter correct password."); return false; } return true; } </script> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><b><font color="#666600">Admin panel</font></b></p> <table width="34%" border="1" align="center" height="137" cellpadding="0" cellspacing="0"> <form name="form1" method="post" onSubmit="return validate();"> <tr> <td height="62" bgcolor="#CCCCCC"><b><font color="#990000">User name :</font></b></td> <td height="62" bgcolor="#CCCCCC"> <input type="text" name="username"> </td> </tr> <tr> <td height="70" bgcolor="#CCCCCC"><b><font color="#990033">Password :</font></b></td> <td height="70" bgcolor="#CCCCCC"> <input type="password" name="password"> </td> </tr> <tr> <td height="26" bgcolor="#CCCCCC"> </td> <td height="26" bgcolor="#CCCCCC"> <input type="submit" name="Submit"> </td> </tr> </form> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
naveenbj Posted January 10, 2008 Author Share Posted January 10, 2008 your code should be , you missed out a "{" for the validate function and misspelled the name of the form <html> <head><title>admin</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript"> function validate() { if(document.form1.username.value!='jimmy') { alert("Enter correct user name."); return false; } if(document.form1.password.value!='123456') { alert("Enter correct password."); return false; } return true; } </script> </head> <body bgcolor="#FFFFFF" text="#000000"> <p><b><font color="#666600">Admin panel</font></b></p> <table width="34%" border="1" align="center" height="137" cellpadding="0" cellspacing="0"> <form name="form1" method="post" onSubmit="return validate();"> <tr> <td height="62" bgcolor="#CCCCCC"><b><font color="#990000">User name :</font></b></td> <td height="62" bgcolor="#CCCCCC"> <input type="text" name="username"> </td> </tr> <tr> <td height="70" bgcolor="#CCCCCC"><b><font color="#990033">Password :</font></b></td> <td height="70" bgcolor="#CCCCCC"> <input type="password" name="password"> </td> </tr> <tr> <td height="26" bgcolor="#CCCCCC"> </td> <td height="26" bgcolor="#CCCCCC"> <input type="submit" name="Submit"> </td> </tr> </form> </table> </body> </html> Rajivgonsaves thanks a lot . Im getting the output. But still im not able to find out wher i was wrong?? If you can point out the particular line for me it would be gr8 help from you. ------- Regards Nj Quote Link to comment Share on other sites More sharing options...
naveenbj Posted January 10, 2008 Author Share Posted January 10, 2008 Ok Rajive i got it no need to explain. A very small mistake which i did:( But again thakns a lot to you all Reagrds, Nj Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.