music_lp90 Posted December 5, 2007 Share Posted December 5, 2007 edit: Nevermind, I figured it out. I didn't realize I needed to write "return" inside of the onsubmit eventHi, I'm pretty new to JavaScript and am trying to make the most basic form validation, yet it is not working. The problem is, it catches the error, but the form still submits after the user clicks ok on the alert box.Here's the code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title><link href="formStyle.css" type="text/css" rel="stylesheet"><script type="text/javascript" language="javascript">function checkForm (passForm) { if (passForm.user.value == "") { alert("You muster enter a user name"); passForm.user.focus(); return false; }}</script></head><body><form onSubmit="checkForm(this)" name="login" action="test.php"> Username: <input type="text" name="user" id="userName" /> <input type="submit" value="Login"></form></body></html> Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.