选择时提交表单(使用 Drupal)

发布于 2024-11-01 06:15:49 字数 1582 浏览 2 评论 0原文

我一辈子也解决不了这个问题。使用 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 技术交流群。

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

发布评论

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

评论(2

っ〆星空下的拥抱 2024-11-08 06:15:49

这应该有效。如果您将下面的代码单独放入一个文件中,它将正常工作:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
  $("#edit-filter").live("change keyup", function () {
    $("#people-blockform").submit();
  });
});
</script>
</head>
<body>
<form id="people-blockform" method="post" accept-charset="UTF-8" action="test.php">
  <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>
</body>
</html>

既然它是单独工作的,那么它一定是其他东西把事情弄乱了。

  • 页面上还有哪些其他表格?
  • 页面上还有哪些其他 Javascript/jQuery?
  • 您确定您提到的 jQuery 已正确包含吗?
  • 您是使用 drupal_add_js() 来包含必需的 .js 文件,还是其他方法?

This should work. If you put the below code into a file on it's own, it will work correctly:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
  $("#edit-filter").live("change keyup", function () {
    $("#people-blockform").submit();
  });
});
</script>
</head>
<body>
<form id="people-blockform" method="post" accept-charset="UTF-8" action="test.php">
  <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>
</body>
</html>

Seeing as this works in isolation, it must be something else which is messing things up.

  • What other forms do you have on the page?
  • What other Javascript/jQuery do you have on the page?
  • Are you sure that the jQuery you mentioned is being included properly?
  • Are you using drupal_add_js() to include the requisite .js files, or another method?
傻比既视感 2024-11-08 06:15:49

检查您的 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.".

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