Reputation: 94
I have one form which i am trying to validate with javascript alert ok! code is -
<form class="testimonialForm" id="testimonialForm" name="testimonialForm"
method="post" enctype="multipart/form-data" action="addtestimonial.php"
onSubmit="return validateForm()">
<li><label for="name">Name <em>*</em></label>
<input name="testimonial_submitter_name" value="{$testimonial_submitter_name}"
id="testimonial_submitter_name"
class="required" minlength="2" placeholder="your name here!"/>
</li>
and the javascript i used is
function validateForm()
{
var v1=document.getElementById("testimonial_submitter_name").value;
var v2=document.getElementById("testimonial_title").value;
if(v1=="")
alert ("enter the name");
}
Though if empty form is submitted it alert what is given to display in alert box.
But the form get submitted!
What is the problem?
How to solve? help me out !
Thanks in advance!
Upvotes: 2
Views: 3076
Reputation: 2845
function validateForm() {
var name = document.getElementById("testimonial_submitter_name").value;
var title = document.getElementById("testimonial_title").value;
if (name == "") {
alert("enter the name");
return false;
}
return true;
}
Upvotes: 2