[英]How do I resolve JavaScript error “not defined”?
This form works in Safari. 此表单可在Safari中使用。 In IE, it mostly works, but I get an error "Object doesn't support this property or method." 在IE中,它通常可以正常工作,但是出现错误“对象不支持此属性或方法”。 on line 240. 在第240行。
In Firefox, no alert box appears, but the following error appears in the error console: 在Firefox中,没有出现警告框,但错误控制台中出现以下错误:
Error: myform is not defined Line: 240 (line 240 is below, starting with the word if) 错误:未定义myform行:240(下面是第240行,以单词if开头)
<script type="text/javascript">
// Validate the form
// Confirm with the visitor the amount he entered is correct
// Submit if OK is pressed
$(document).ready(function() {
$("#myform").validate({
submitHandler:function(form){
if(confirm("Please confirm your donation of $"+ myform.x_Amount.value + " to us.")){
form.submit();
}
}
});
});
// Put grey "no spaces" example text in the credit card number field
$('#x_Card_Num').example('(NoSpaces)', {
className: 'greydefaulttext'
});
</script>
Guess I need to define myform.x_Amount.value. 猜猜我需要定义myform.x_Amount.value。 Have tried doing this in various ways but haven't stumbled across the right location to define it yet, or even the right syntax. 尝试过以各种方式执行此操作,但尚未偶然找到正确的位置来定义它,甚至没有正确的语法。 Thanks for any help. 谢谢你的帮助。
Update: Thanks to fresh eyes from RC and Bobince, it was simply a typo: myform.x_Amount.value should be named form.x_Amount.value - it now works in all browsers. 更新:由于RC和Bobince的崭新眼光,这只是一个错字:myform.x_Amount.value应该命名为form.x_Amount.value-现在它在所有浏览器中都可以使用。
"submit is not a function" means that you named your submit button or some other element submit. “提交不是功能”表示您将提交按钮或其他元素命名为提交。 Rename the button to btnSubmit and your call will magically work. 将按钮重命名为btnSubmit,您的呼叫将神奇地工作。
When you name the button submit, you override the submit() function on the form. 当您将按钮命名为Submit时,您将覆盖表单上的commit()函数。
that fixes your one error. 可以解决您的一个错误。 If by form.x_Amount.value
you want to get the value of a textfield, try it like this: 如果要通过form.x_Amount.value
获取文本字段的值,请尝试如下操作:
document.form_name.element_name.value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.