I have the following HTML code for the alert div:
<div id=formAlert class=alert>
<a class=close data-dismiss=alert>×</a>
<strong>Warning!</strong> Make sure all fields are filled and try again.
</div>
And the following JavaScript:
function validateForm(){
var x=document.forms['register']['username'].value;
if (x==null || x==) {
alert('This is an alert')
return false;
var alertDialog = document.getElementByid(formAlert);
alertDialog.style.display = block;
}
}
The problem with the code is that the alert is showing prematurely, even before the code is called. I can tell the alert is called when the default JavaScript alert box pops up. Ideally, when validateForm()
is called, I want the alert to show up. validateForm()
is called when the form is submit.
EDIT: As requested, here is the code triggering the validateForm():
<form name=register action= onSubmit=return validateForm() method=post>
</form>
Now that I've solved the issue of calling it, how do I hide the div until it's called by the JavaScript, as it's already showing before the code executes.