I am trying to integrate a javascript form validation into a pet project of mine and am stumbling over this:
function validateForm() {
if (this.firstname.value == "") {
document.getElementById("testingline").innerHTML = '<div class="alert alert-danger alert-dismissable"><span>'+missing+'</span></div>';
this.firstname.focus();
return false;
}
return true;
}
If the line document.getElementById is omitted, the form is not submitted on click, while with the line the form is submitted.
What am I doing wrong?
The function is called through this:
<form name="helperform" role="form" method="get" action="thanks.php"
onsubmit="return validateForm(this)">
and the line should be added to this:
<div class="col-md-6 col-md-offset-3" id="testingline" name="testline"></div>
Thanks for helping!
Daniel