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

使用.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.

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵