使用 Javascript 提交表单

发布于 2024-11-06 09:19:06 字数 1282 浏览 1 评论 0原文

我觉得不得不问这个总部真的很愚蠢,但我不知道为什么这段代码不起作用,它真的很简单叹息

我得到了以下JavaScript当我从任一下拉菜单中选择并且表单未提交时出错。

未捕获的类型错误:对象的属性“提交”#不是函数

<form action="categories/view/52" method="post" accept-charset="utf-8" id="myform" name="myform"> 
<select name="sort" ID="sort_type" onchange='document.forms["myform"].submit();'>   
  <option value="label">Sort</option> 
  <option value="price-low-high">Price: Low - High</option> 
  <option value="price-high-low" selected="selected">Price: High - Low</option> 
  <option value="name-a-z">Name A - Z</option> 
  <option value="name-z-a">Name Z - A</option> 
  <option value="date-added-new">Date Added - New</option>  
  <option value="date-added-old">Date Added - Old</option> 
</select> 
<select name="limit" ID="sort_type" onchange='document.forms["myform"].submit();'>   
  <option value="items_3" selected="selected">3</option> 
  <option value="items_50">50</option> 
  <option value="items_100">100</option> 
  <option value="items_all">all</option> 
</select> 
<input type="submit" name="submit" value="submit"  />
</form> 

I feel really silly for having to ask this head desk but I've got no idea why this code isn't working it really simple sigh

I'm getting the following JavaScript error when I select from either of the drop downs and the form doesn't submit.

Uncaught TypeError: Property 'submit' of object # is not a function

<form action="categories/view/52" method="post" accept-charset="utf-8" id="myform" name="myform"> 
<select name="sort" ID="sort_type" onchange='document.forms["myform"].submit();'>   
  <option value="label">Sort</option> 
  <option value="price-low-high">Price: Low - High</option> 
  <option value="price-high-low" selected="selected">Price: High - Low</option> 
  <option value="name-a-z">Name A - Z</option> 
  <option value="name-z-a">Name Z - A</option> 
  <option value="date-added-new">Date Added - New</option>  
  <option value="date-added-old">Date Added - Old</option> 
</select> 
<select name="limit" ID="sort_type" onchange='document.forms["myform"].submit();'>   
  <option value="items_3" selected="selected">3</option> 
  <option value="items_50">50</option> 
  <option value="items_100">100</option> 
  <option value="items_all">all</option> 
</select> 
<input type="submit" name="submit" value="submit"  />
</form> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2024-11-13 09:19:06

因为您已经:

<input type="submit" name="submit" value="submit"  />

提交功能已被该 HTMLElementNode 破坏。

简单的解决方案是重命名或删除该名称。

<input type="submit" value="submit"  />

如果您无法重命名它(因为您的服务器端代码取决于提交的值,并且您无法更改服务器端代码),那么您可以:

document.createElement('form').submit.call(document.forms["myform"]);

Since you have:

<input type="submit" name="submit" value="submit"  />

The submit function has been clobbered with that HTMLElementNode.

The simple solution is to rename it, or remove the name.

<input type="submit" value="submit"  />

If you can't rename it (because you have server side code that depends on that value being submitted and you can't change the server side code) then you can:

document.createElement('form').submit.call(document.forms["myform"]);
沉默的熊 2024-11-13 09:19:06

尝试调用 form.submit() 时出错的原因是您的提交按钮被称为“提交”。这意味着 Form 对象的“submit”属性现在是对提交按钮的引用,覆盖表单原型的“submit”方法。

重命名提交按钮将允许您调用 Submit() 方法而不会出现错误。

<input type="submit" name="submitEle" value="submit"  />

应该有效

The reason for the error when trying to call form.submit() is that your submit button is called "submit". This means that the "submit" property of your Form object is now a reference to the submit button, overriding the "submit" method of the form's prototype.

Renaming the submit button would allow you to call the submit() method without error.

<input type="submit" name="submitEle" value="submit"  />

Should work

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文