JavaScript Submitting with onclick |
JavaScript Submitting with onclick |
-darkness_complex- |
Nov 11 2009, 05:59 PM
Post
#1
|
Group: Members Posts: 1 Joined: 11-November 09 Member No.: 10,315 |
I'm working on writing something that will preform a Javascript 'check' on all data submitted and then posting it all as $_POST data. Right now the submit button doesn't seem to be working, it will fire the java-script, but cannot seem to move past that point.
<script type="text/Javascript"> function myfunction(email, password) { if(email == ""){ alert("Must fill in email field."); return false; } else if(password == "") { alert("Must fill in password field."); return false; } else return true; } </script> . . . echo '<html> <form method="POST" id="login" name="login" action="login.php"> <p>Email: <input type="text" name="email" size="25"></p> <p>Password: <input type="password" name="password" size="25"></p> <p><input type="button" value="Submit" name="Button 1" onclick="if(myfunction(login.email.value, login.password.value)==true){login.email.submit();login.password.submit();}"> <input type="reset" value="reset" onclick="return confirm(\'Are you sure you want to reset the form?\')" name="Button 2"></p> </form> </html>'; |
Christian J |
Nov 12 2009, 04:42 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Try using the onsubmit event of the form element: http://www.javascriptkit.com/javatutors/form6.shtml
|
Lo-Fi Version | Time is now: 24th April 2024 - 12:08 AM |