简体   繁体   English

在复选框旁边添加文本

[英]Add text beside checkbox

when click the checkbox another modal will pop up for the quantity of the selected value and I check Geda Jumuad and add "2" as quantity value but then the value '2' was put in the beginning of the checboxes . 当单击该复选框时,将弹出另一个模态以显示所选值的数量,我检查Geda Jumuad并添加“ 2”作为数量值,但随后将值“ 2”放在复选框的开头。 . I want to put the quantity value beside the selected checkbox.. please help me. 我想将数量值放在选中的复选框旁边..请帮助我。 heres my code 这是我的代码

<b>Menu: </b>
<br>
<div class="menucontainers" style="background: #fff; border-style: solid; border-width: 2px; border-color:#ccccff; width: 400px; height:150px; overflow:auto;">
  <!-- <img src ="../1.jpg" class="img-rounded"> -->

  <ul>
      <?php
                          include ('myConnection.php');

                          $query = "Select * from menu_category order by menu_cat_name";
                          $result = mysql_query($query);
                          while ($row = mysql_fetch_array($result)) {
                              $menucatname = $row['menu_cat_name'];
                              $menucatid = $row['menu_cat_id_inc'];

                        ?>
          <li class="dropdownz" style="border-style: solid;border-color: white; border-bottom: 2px; border-left: 2px; border-right: 2px">
              <a href="#" data-toggle="dropdownz" style="font-size:15px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i id = "arrow" class="icon-arrow"></i><?php echo "$menucatname"; ?></a>
              <ul id="ddownz-menu" class="dropdownz-menu">
                  <li>
                      <?php
                              $query2 = "Select * from menu where menu_cat_id_inc = '$menucatid' order by menu_name";
                              $result2 = mysql_query($query2);
                              $countme = 0;
                              while ($row2 = mysql_fetch_array($result2)) {
                                  $menuname = $row2['menu_name'];
                                  $price = $row2['price'];                          
                              if ($countme % 2 == 0)
                              {
                            ?>
                          <div class="col col-md-6">
                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                              <input type="checkbox" id="newmenu" name="cbox[]" style="font-size:15px" value="<?php echo $row2['menu_id_inc'];?>">
                              <?php

                                      echo '<span id = "quantity" style = "color:black;"></span>'. " " . "$menuname";
                                  ?>

                          </div>
                          <?php
                              }
                              else
                              {

                              ?>
                              <div class="col col-md-4">
                                  <input type="checkbox" id="newmenu" name="cbox[]" value="<?php echo $row2['menu_id_inc'];?>">

                                  <?php
                                      echo '<span id = "quantity" style = "color:black;"></span>'. " " . "$menuname";
                                  ?>
                              </div>

                              <?php
                              }
                              }
                                  ?>
                  </li>
              </ul>
          </li>
          <?php
                          }

                        ?>
  </ul>
</div>


and for javascript. 和javascript。 .

$("#qtyok").click(function () {
    var id = $("#menuid").val();
    var qty = $("#qtybox").val();
    if (qty != '') {
        $("#loaderz").show();
        $.post("fm_valuemenuload.php", {
                id: id,
                qty: qty

            },
            function (data, status) {
                $("#loaderz").hide();
                $("#modalQty").modal('hide');
                $("#message").html('Added');
                document.getElementById('quantity').innerHTML = qty;
                price += data * qty;
                $("#newprice").val(price.toFixed(2));
                $("#modalSUCCESS").modal('show');
                setTimeout(func1, 3000);

            });
    }
});

` `

I might be misunderstanding your problem but... I think you just got it in the wrong order. 我可能误解了您的问题,但是...我想您只是以错误的顺序得到了它。 Place the span after the $menuname. 将跨度放在$ menuname之后。

Instead of 代替

echo '<span id = "quantity" style = "color:black;"></span>'. " " . "$menuname";

Do

echo "$menuname".' <span id = "quantity" style = "color:black;"></span>';

You also must assign unique ids to your spans. 您还必须为范围分配唯一的ID。 Although your checkboxes are dynamic, you can for example retrieve the value of those checkboxes and append it to 'quantity'. 尽管您的复选框是动态的,但是例如,您可以检索这些复选框的值并将其附加到“数量”中。 You will have ids 'quantity1', 'quantity2', 'quantity3' produced. 您将产生ID“ quantity1”,“ quantity2”,“ quantity3”。 Change the previous line of code to 将上一行代码更改为

echo "$menuname".' <span id = "quantity'.$row2['menu_id_inc'].'" style = "color:black;"></span>';

You will also have to do something similar in your javascript. 您还必须在JavaScript中执行类似的操作。 Retrieve the checkbox value number in a javascript variable, and append it to 'quantity' here 检索javascript变量中的复选框值编号,并将其附加到此处的“数量”中

document.getElementById('quantity' + value).innerHTML = qty;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM