Jump to content

Having trouble with simple form validation


music_lp90

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...