选择时提交表单(使用 Drupal)
我一辈子也解决不了这个问题。使用 Drupal 并有一个表单,我想在用户选择一个选项后提交该表单。 HTML 是
<form id="people-blockform" method="post" accept-charset="UTF-8" action="/people">
<div>
<div id="edit-filter-wrapper" class="form-item">
<label for="edit-filter">Filter: </label>
<select id="edit-filter" class="form-select" name="filter">
<optgroup label="label1">
<option value="all">Everyone</option>
<option value="option1">option1</option>
<option value="option2">option2</option>
</optgroup>
<optgroup label="Location">
<option value="loc1">loc1</option>
<option value="loc2">loc2</option>
</optgroup>
</select>
</div>
<input type="submit" class="form-submit" value="Filter" id="edit-submit" name="op">
<input type="hidden" value="form-ccd2e26e54becdc164411311ff397989" id="form-ccd2e26e54becdc164411311ff397989" name="form_build_id">
<input type="hidden" value="cb83794b5b00da15e546e12ec5499e64" id="edit-people-blockform-form-token" name="form_token">
<input type="hidden" value="people_blockform" id="edit-people-blockform" name="form_id">
</div>
</form>
,我尝试使用的 jQuery 是这样的:
$(function () {
$("#edit-filter").live("change keyup", function () {
$("#people-blockform").submit();
});
});
非常感谢任何帮助
I can't work this out for the life of me. Using Drupal and have a form that I'd like to submit once the user has selected one option.
HTML is
<form id="people-blockform" method="post" accept-charset="UTF-8" action="/people">
<div>
<div id="edit-filter-wrapper" class="form-item">
<label for="edit-filter">Filter: </label>
<select id="edit-filter" class="form-select" name="filter">
<optgroup label="label1">
<option value="all">Everyone</option>
<option value="option1">option1</option>
<option value="option2">option2</option>
</optgroup>
<optgroup label="Location">
<option value="loc1">loc1</option>
<option value="loc2">loc2</option>
</optgroup>
</select>
</div>
<input type="submit" class="form-submit" value="Filter" id="edit-submit" name="op">
<input type="hidden" value="form-ccd2e26e54becdc164411311ff397989" id="form-ccd2e26e54becdc164411311ff397989" name="form_build_id">
<input type="hidden" value="cb83794b5b00da15e546e12ec5499e64" id="edit-people-blockform-form-token" name="form_token">
<input type="hidden" value="people_blockform" id="edit-people-blockform" name="form_id">
</div>
</form>
and the jQuery I'm trying to use is this:
$(function () {
$("#edit-filter").live("change keyup", function () {
$("#people-blockform").submit();
});
});
Any help is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效。如果您将下面的代码单独放入一个文件中,它将正常工作:
既然它是单独工作的,那么它一定是其他东西把事情弄乱了。
This should work. If you put the below code into a file on it's own, it will work correctly:
Seeing as this works in isolation, it must be something else which is messing things up.
检查您的 jQuery 版本。我现在正在安装的 D6.16 安装上有 1.2.6,但是
.live
处理程序直到 1.3 才添加(http://api.jquery.com/live/ )。因此,您的代码返回“TypeError:表达式'$("#edit-field-servicegroup-value").live' [undefined]
的结果不是函数。”。Check your jQuery version. I have 1.2.6 on the D6.16 install I'm working on right now, but the
.live
handler wasn't added until 1.3 (http://api.jquery.com/live/). So your code returns "TypeError: Result of expression'$("#edit-field-servicegroup-value").live' [undefined]
is not a function.".