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 Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/ Share on other sites More sharing options...
rajivgonsalves Posted January 10, 2008 Share Posted January 10, 2008 post your full code !! Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435381 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 Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435385 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. Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435387 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?? Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435388 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? Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435389 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 Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435393 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> Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435394 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 Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435399 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 Link to comment https://forums.phpfreaks.com/topic/85326-solved-why-this-script-is-not-working-for-me/#findComment-435400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.