javascript - JS validation on form -


i have form trying validate js. problem life of me can’t work.

can tell me i’m going wrong? in example below rying validate email field.

regards, marc

function validateemail() {      var x = document.forms["myform"]["email"].value;  	if (x == null || x == "") {          alert("name must filled out");          return false;      }  }
#contact-area {    	width: 500px;  	max-height:200px;  	margin-top: 0px;  	float:left;  }    #contact-area input, #contact-area textarea {    	padding: 3px;  	width: 520px;  	font-family:'lato', sans-serif;  	font-size: 14px;  	margin: 0px 0px 0px 0px;  	border: 1px solid #ccc;  }    #contact-area textarea {    	height: 90px;  }    #contact-area textarea:focus, #contact-area input:focus {    	border: 1px solid #ffc423;  }    #contact-area input.submit-button {    	width: 100px;  	float: left;  	background-color:#ffc423;  	color:black;  	margin-top:13px;  	cursor:pointer;  }    #contact-area input.submit-button:hover {  	background-color:#002b51;  	color:white;  }    label {    	float:left;  	text-align:left;  	margin-right:15px;  	width:100px;  	padding-top:10px;  	padding-bottom:5px;  	font-size:15px;  	color:#ffc423;  	font-weight:700;  }    textarea {       resize: none;   }
<div id="contact-area">  			  						<form method="post" action="contactengine.php" name="myform" onsubmit="return contact-validation()">  						<label for="name">name:</label>  						<input type="text" name="name" id="name">  				  						<label for="company">company:</label>  						<input type="text" name="company" id="company">  	  						<label for="email">email:</label>  						<input type="email" name="email" id="email">  				  						<label for="message">message:</label>  						<textarea name="message" rows="20" cols="20" id="message" title="your message | max 300 characters"></textarea>    						<input type="submit" name="submit" value="submit" class="submit-button">  						</form>  			  					<div style="clear: both;"></div>  			  					</div>

this wrong:

onsubmit="return contact-validation()"> 
  1. you have no javascript method called contact-validation().

  2. even if did, dashes not valid in function names.

try instead:

onsubmit="return validateemail()"> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -