我的表单ID是“ requestquote”。当我提交表单时,我在控制台中收到一个错误(“ formSub没​​有值”)。表单过程已通过我的PHP操作文件完成,但我也需要运行这部分JavaScript。任何建议,将不胜感激。

<script>
_opt.push(['instrument','requestquote']);

var formSub = $('requestquote');
console.log(formSub);

formSub.submit(function(){

_opt.modifyFormParameters = function(parameters){

parameters["_orig_action"] = document.getElementById("_orig_action").value;
parameters["_opt_vid"] = document.getElementById("_opt_vid").value;
parameters["_opt_visit"] = document.getElementById("_opt_visit").value;
parameters["_opt_cid"] = document.getElementById("_opt_cid").value;
parameters["_opt_url"] = document.getElementById("_opt_url").value;
parameters["_opt_paget"] = document.getElementById("_opt_paget").value;
parameters["first_name"] = document.getElementById("name").value;
parameters["company"] = document.getElementById("company").value;
parameters["website"] = document.getElementById("url").value;
parameters["email"] = document.getElementById("email").value;
parameters["phone"] = document.getElementById("phone").value;

return parameters;
};
_opt.push(['submit', 'requestquote']);
_opt.the_form = this;

setTimeout(function(){ _opt.the_form.submit(); } , 1000);
return false;
});
</script>


这是表格代码

<form id="requestquote" action="/quote-process/contact_pr_EPH.php" method="post">

最佳答案

如果是表单的ID,则应为:

$('#requestquote');甚至$('form#requestquote');

$()的作用不只是GetElementByID
阅读jQuery(真正的Sizzle)选择器:http://api.jquery.com/category/selectors/

10-07 21:31