Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript form validation 1

Status
Not open for further replies.

khanza

Technical User
Feb 20, 2003
70
US
Code:
<html>
<head>
<script language="javascript">
function validate(formObj){
 if(formObj.phone.value.length != 0)
   {
    document.register.submit()
 }
 
  else {
    alert("Please fill in your telephone number")
 }
}
</script>
</head>
<body>
	<form  name="register" action="tekconfirm.php" method="post">
		<table>
			<tr><td>Name:</td><td><INPUT type="text" name="name"></td></tr>
			<tr><td>Address:</td><td><INPUT type="text" name="address"></td></tr>
			<tr><td>City:</td><td><INPUT type="text" name="city"></td></tr>
			<tr><td>Zip:</td><td><INPUT type="text" name="zip"></td></tr>
			<tr><td>Phone:</td><td><INPUT type="text" name="phone"></td></tr>
			<tr><td>Email:</td><td><INPUT type="text" name="email"></td></tr>
			<tr><td colspan="2"><select name="pass" size="1" >
			<option value="3-day" label="3-day" selected>Full 3-day Package</option>
			<option value="satonly" label="sat-only">Saturday Only</option>
			<option value="workshops" label="Workshops Only">Workshops Only</option>
			<option value="satdin" label="Saturday Dinner, Show and dance">Saturday Dinner, Show and dance $60</option>
			</select></td></tr>
		</table><br>
<br>Dinner Preference (Excluding the Workshop only pass):<br>
	<select name="dinner" size="1" >
	<option value="beef, tbd" label="beef, tbd" selected>Beef, TBD</option>
	<option value="TBD" label="TBD">TBD</option>
	<option value="Vegetarian" label="Vegetarian">Vegetarian</option>
	</select><br>
<br>Dance Preference:
	<select name="preference" size="1" >
	<option value="line" label="line" selected>Line</option>
	<option value="swing" label="swing">Swing</option>
	<option value="country" label="country">Country</option>
	<option value="Ballroom" label="Ballroom">Ballroom</option>
	</select><br>
<br><input type="button" name="submit" onclick="validate(register)" value="submit" >
</form>
</body>
</html>


Shows alert box if the phone part is empty, but wont' submit if something is in the phone part....

Here's a pastebin


Thanks guys
 

It's because you have an input named "submit":

Code:
<input type="button" name="submit" onclick="validate(register)" value="submit" >

Change it to this:
Code:
<input type="button" name="[COLOR=red]_submit[/color]" onclick="validate(register)" value="submit" >

And you will be sorted.

Jeff

 
<br><input type="button" name="submit" onclick="validate('register')" value="submit" >


Maybe is that, the single quotes
 
Thanks baby jeffy -- I can't believe it was that simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top