简体   繁体   English

javascript 无法使用 ID 标记定位表单

[英]javascript unable to locate a form using the ID tag

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: http://m.lancasterpainting.com/contact.php这是我的问题:我正在尝试设置一个内置验证码的简单移动联系表单。我正在处理的页面可以在这里找到: http://m.lancasterpainting.com/contact.php

I'm using the following php contact form: http://www.html-form-guide.com/contact-form/php-email-contact-form.html我正在使用以下 php 联系表: http://www.html-form-guide.com/contact-form/php-email-contact-form.html

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".正如您在访问该页面时看到的那样,每次访问该页面时,都会出现一个错误,显示“错误:无法获取表格 object contact_form”。

I cannot--for the life of me--figure out why the javascript can't find the form I pass it.我无法——我这辈子——弄清楚为什么 javascript 找不到我传递给它的表格。

I call the function that generates this error at the top of the page:我在页面顶部调用生成此错误的 function:

var frmvalidator  = new Validator("contact_form");

The form I'm referencing is as follows in the HTML code:我引用的表单在 HTML 代码中如下所示:

<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: http://m.lancasterpainting.com/scripts/gen_validatorv31.js生成错误的调用 function 可以在此处的 external.js 文件中找到: http://m.lancasterpainting.com/scripts/gen_validatorv31.js

Is there something that I am simply not seeing?有什么我根本看不到的吗? Why can't the javascript locate the form?为什么 javascript 找不到表格?

Thanks so much to anyone that helps with this.非常感谢任何为此提供帮助的人。

  1. There's no form named contact_form , but one with id= sendEmail .没有名为contact_form的表单,只有一个 id= sendEmail的表单。 You may wonder, but div is not a form: <div id="contact_form"您可能想知道,但 div 不是表单: <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. Javascript 代码运行得太早,文档未准备好,调用表单验证器代码时document.forms集合甚至不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM