dongzhan9100 2016-01-09 16:57
浏览 549
已采纳

使用.serializeArray从所有选中的复选框中获取值

SOLVED I did't use "name" in input field. When I add name to input i worked instantly.

I have a medium size menu with a few subcategories and a lot of checkboxes. I work on custom CMS with php, mysql and jquery/javascript.

The menu is in a form with a button "Save" that needs to get all values from checked checkboxes.

On button I use onclick function that leads to my class in which I use those id's and store them in a table.

<input type="submit" value="Save" class="save-butt" onclick="sjx('domain', $( ':checkbox' ).serializeArray()); return false;">

It does not work; i don't get any error but it seems that the value is not sent. Here is my menu code if it helps.

          <div class="personal-right-box">
        <ul class="doe-list">

        <?php 
        $mainCat = Db::query('SELECT * FROM categories WHERE parent_id = 0 ORDER BY orderby DESC');
        foreach ($mainCat as $main) { ?>

          <li>
            <span><i class="fa fa-caret-down toggle-down"></i><?php echo $main['title_hr']; ?></span>
            <ul class="doe-list-sub">
              <?php 
              $subCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$main['id'].' ORDER BY title_hr ASC');
              foreach ($subCat as $sub) { ?>
              <li>                    
                <input type="checkbox" name="" id="aaeroplanes-b1-b2" value="<?php echo $sub['id']; ?>">
                <label for="aaeroplanes-b1-b2"><?php echo $sub['title_hr']; ?></label>
                <i class="fa fa-caret-down toggle-down"></i>
                <ul class="doe-list-sub">
                  <?php 
                  $subsubCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$sub['id'].' ORDER BY title_hr ASC');
                  foreach ($subsubCat as $subsub) { ?>
                  <li>
                    <input type="checkbox" name="" id="piston-engine-aeroplanes-b1-2" value="<?php echo $subsub['id']; ?>">
                    <label for="piston-engine-aeroplanes-b1-2"><?php echo $subsub['title_hr']; ?></label>
                    <i class="fa fa-caret-down toggle-down"></i>
                    <ul class="doe-list-sub">
                      <?php 
                      $subsubsubCat = Db::query('SELECT * FROM categories WHERE parent_id = '.$subsub['id'].' ORDER BY title_hr ASC');
                      foreach ($subsubsubCat as $subsubsub) { ?>
                      <li>
                        <input type="checkbox" name="" id="cessna" value="<?php echo $subsubsub['id']; ?>">
                        <label for="cessna"><?php echo $subsubsub['title_hr']; ?></label>
                        <i class="fa fa-caret-down toggle-down"></i>
                        <ul class="doe-list-sub group">
                          <?php 
                          $items = Db::query('SELECT * FROM categories WHERE parent_id = '.$subsubsub['id'].' ORDER BY title_hr ASC');
                          foreach ($items as $item) { ?>
                          <li class="col-1-3">
                            <input type="checkbox" name="" id="" value="<?php echo $item['id']; ?>">
                            <label for=""><?php echo $item['title_hr']; ?></label>
                          </li>
                          <?php } ?>
                        </ul>
                      </li>
                      <?php } ?>
                    </ul>
                  </li>
                  <?php } ?>
                </ul>
              </li>
              <?php } ?>
            </ul>
          </li>

        <?php } ?>
        </ul><!-- end of .doe-list -->
        <span class="save-button-form">
          <input type="submit" value="Save" class="save-butt" onclick="sjx('domain', $( ':checkbox' ).serializeArray()); return false;">
        </span>
      </div>

Thank you for your help.

  • 写回答

1条回答 默认 最新

  • doz22551 2016-01-09 17:08
    关注

    serialize use name first and if it doesn't find it then it goes for id. In your case you have a blank name, and so in your result.
    you can either copy the same content in name or remove it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了