I have a small form page, with a submit button and an onclick event.
[HTML]<input type="button" value="Sign Up!" onClick="signUp();">[/HTML]
This worked just fine until I added a new regex function, but now it returns an "Error: Object expected" when I click it. I've tried moving the javascript function to the top of the page (inside the head tags) instead of the bottom (above the body tag, both above and below the form tag), all with the same error result. I've even tried taking out the new function and returning to normal; no dice. However, if I simply put an alert in the onclick, it works; any function I put there doesn't, even a dud function that only contains an alert.
Any idea what might be happening? Here's the basic page format and function:
[HTML]
<html>
<head>
</head>
<body>
<div>
<form>
lots of stuff
<input type="button" value="Sign Up!" onClick="alert('click');signUp();">
</form>
</div>
<script language="javascript">
function signUp()
{
var firstname=document.getElementById('firstName');
var lastname=document.getElementById('lastName');
var email=document.getElementById('Email');
var phone=document.getElementById('phone');
if(firstname.value==''||lastname.value==''||email. value==''||phone.value='')
{alert('Please enter all required fields.');}
else
{
if(checkEmail(email.innerText)){
do stuff
}
}
}
function checkEmail(email){
var emailRegex=/^(\w)+.?(\w)*@(\w)+.?(\w)+/;
if(!email.match(emailRegex)){alert('Please enter a valid email address.');return false;}
return true;
}
</script>
</body>
</html>
[/HTML]