dongzhan9100
2016-01-09 16:57
浏览 442

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

    打赏 评论

相关推荐 更多相似问题