Gossamer Forum
Home : General : Internet Technologies :

help debugging javascript

Quote Reply
help debugging javascript
Been banging my head against the wall, can't figure this one out...

I've got a simple form, just trying to validate certain required fields before submission. It worked fine until I started checking one of the fields against a regex... Now it just gives me object expected errors. Any advice would be very much appreciated:

Code:
<script language="javascript" type="text/javascript">
function appVerify() {
var einFlag = false;
einFlag = /^[0-9]{9}$/.test(document.myform.fiscal_legalTaxID.value);
if(document.myform.fiscal_legalName.value=="" ||
document.myform.fiscal_legalTaxID.value=="" ||
!document.myform.fiscal_projectCategory.selectedIndex ||
document.myform.fiscal_projectDescription.value=="" ||
document.myform.fiscal_qualifications.value=="" ||
document.myform.fiscal_contactChecks.value=="" ||
document.myform.fiscal_contactReceipts.value=="") {
alert("Please fill in all required fields.");
return false;
} elseif(!einFlag) {
alert("Please enter a valid EIN without hyphens.");
return false;
} else {
document.myform.submit();
}
}
</script>

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund

Last edited by:

hennagaijin: Jan 28, 2003, 12:54 PM
Quote Reply
Re: [hennagaijin] help debugging javascript In reply to
Try removing that einflag line and then where you have:

elseif (!einflag) {

....use:

elseif (! document.myform.fiscal_legalTaxID.value.match(/^[0-9]{9}$/)) {

Last edited by:

Paul: Jan 28, 2003, 1:01 PM
Quote Reply
Re: [Paul] help debugging javascript In reply to
Thanks for your help. Unfortunately, still the same error - object expected. Any other thoughts?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] help debugging javascript In reply to
It must be a different part of the code as that regex code is valid.

The only thing I can see that it may be is:

document.myform.fiscal_projectCategory.selectedIndex

Try removing that part just to test.
Quote Reply
Re: [Paul] help debugging javascript In reply to
Okay, so I ended up going through bit by bit to determine the exact part that caused it to fail. Turns out it was the addition of an elseif section. If I put it all in that original if clause, it works fine. How's that for bizarre? Just goes to show how little I know about javascripting, I guess...

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] help debugging javascript In reply to
Just happened acrossed this. I know its not an issue anymore but I believe the problem was actually the difference between "elseif" and "else if".
"elseif" is not a valid Javascript statement but instead is mistaken for a variable.

"else if" is the correct use.

In fact when I first started reading the post, I thought that "elseif" was a variable.

Correct Usage:

if (condition) {
action;
}

else if (condition) {
action;
}

else {
action;
}

Just for future reference.

By the way, Netscape offers a JavaScript console for debugging. If the proposed statement is incorrect, and believed to be a variable, it will say:
Error: foo is not defined
(defined suggest variable)

Error: syntax error
(statement used incorrectly)

Hope this helps in the future.
beetlemanTongue

Marcus L. Griswold