By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

Button onclick won't access javascript functions

P: 3
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]
Apr 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: 3
Fixed now - in case anyone is curious, it didn't seem to like me using "phone" as a variable.
Apr 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.