I have a form and below is code
And when submit is clicked it returns true rather that displaying the
textfiled to empty, it should give some error.
Its a simple form validation
html
<form name="rt-form2" method="post" onsubmit="return validateform();">
<input type="text" value="Name" name="name2" id="name1"><br>
<input type="text" value="Email" name="Email" id="Email1"><br>
<input type="text" value="Phone Number" name="phone" id="phone1"><br>
<input type="submit" value="submit" name="submitm" class="submit-btn">
</form>
and javascript validation
<script type="text/javascript">
function validateform(){
alert("Submit button is clicked");
if(document.rt-form2.name2.value.length < 1) {
alert("Enter name");
return false;
}
else {
alert("Submitting");
return true;
}
}
</script>
Dude your script is correct. Just remove the hyphen from your form name and you’re good to go!