javascript unable to locate a form using the ID tag

Go To


Here's my problem: I'm trying to set up a simple mobile contact form with a captcha built in. The page I'm working on can be found here:

I'm using the following php contact form:

I want to first say that I'm not the only one to run into this problem. After googling the issue, I've found multiple people struggling with this, but no-one seems to have an answer.

Now for the problem...

As you can see if you visit the page, each time the page is accessed, an error appears that says "Error: couldnot get Form object contact_form".

I cannot--for the life of me--figure out why the javascript can't find the form I pass it.

I call the function that generates this error at the top of the page:

var frmvalidator  = new Validator("contact_form");

The form I'm referencing is as follows in the HTML code:

<div data-role="page" data-theme="e" id="contact_form" name="contact_form" data-position="inline">

And the function that is called that generates the error can be found in an external .js file here:

Is there something that I am simply not seeing? Why can't the javascript locate the form?

Thanks so much to anyone that helps with this.

2012-04-04 05:22
by ihake


  1. There's no form named contact_form, but one with id=sendEmail. You may wonder, but div is not a form: <div id="contact_form"
  2. Javascript code is run too early, document isn't ready and document.forms collection is even not available when form validator code is called.
2012-04-04 05:27
by kirilloid
I'm an idiot. Don't know why I didn't notice that about the div. As for #2, that was also helpful. I didn't realize that. I changed both those things and it's working now. Thanks - ihake 2012-04-04 05:34