<script language="javascript" type="text/javascript"> function validateForm() { document.getElementById('errorDiv').innerHTML=""; var errorDiv = document.getElementById('errorDiv'); var email = document.getElementById('email').value; var name = document.getElementById('name').value; var comment = document.getElementById('comment').value; var feedbackTypeindex = document.getElementById('FeedbackType').selectedIndex; var subject = document.getElementById('subject').value; apos=email .indexOf("@"); dotpos=email .lastIndexOf("."); var errorDiv = document.getElementById('errorDiv'); if(feedbackTypeindex == 0) { //alert("Please select feedback type"); //document.getElementById('errorDiv').innerHTML="<li><font color='red'>Please select feedback type</font></li>"; errorDiv.innerHTML = "<li><font color='red'>Please select feedback type</font></li>"; return false ; } if(name== null || name=="") { //alert("Please enter your name"); errorDiv.innerHTML = "<li><font color='red'>Please enter your name</font></li>"; return false; } if(email == null || email =="") { //alert("Please enter email address"); errorDiv.innerHTML = "<li><font color='red'>Please enter email address</font></li>"; return false; } else if (apos<1||dotpos-apos<2) { //alert("Please enter valid email address, ie.:yourname@yourdomain.com"); errorDiv.innerHTML = "<li><font color='red'>Please enter valid email address, ie.:yourname@yourdomain.com</font></li>"; return false; } if(subject == null || subject=="") { //alert("Please enter the subject"); errorDiv.innerHTML = "<li><font color='red'>Please enter the subject</font></li>"; return false; } if(comment== null || comment=="") { //alert("Please enter the message"); errorDiv.innerHTML = "<li><font color='red'>Please enter the message</font></li>"; return false; } } </script> <div class="content" > <div><table border="0"><form name="contacts" action="A PHP File for Validation" method="post" onSubmit="return validateForm();"><tr><td colspan="2">feedback type</td><td><select name="FeedbackType" id="FeedbackType"><option value="0">- select -</option> <option value="Sponsership">sponsorship</option> <option value="ads">Advertise</option> <option value="others">Others</option> </select></td></tr><tr><td colspan="2">name</td><td><input type="text" name="name" id="name" value="" maxlength="30" /></td></tr><tr><td colspan="2">email</td><td><input type="text" name="email" id="email" value="" maxlength="30" /> example: user@domain.com</td></tr><tr><td colspan="2">subject</td><td><input type="text" name="subject" id="subject" value="" maxlength="30" /></td></tr><tr><td colspan="2">comments</td><td><textarea name="comment" id="comment" rows="5" cols="30"></textarea></td></tr><tr><td colspan="2"></td><td><input type="submit" value="send" style="width:100px" /></td></tr></form><tr><div id="errorDiv" name="errorDiv" style="margin-left:15px;" ></div> </tr></table></div></div>
No comments:
Post a Comment