Hiển thị các bài đăng có nhãn Checkbox. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Checkbox. Hiển thị tất cả bài đăng

Thứ Ba, 23 tháng 12, 2025

Checkbox Limit - chọn giới hạn trong checkbox

 


<!DOCTYPE html>

<html lang="vi">

<head>

  <meta charset="UTF-8">

  <title>Checkbox Dropdown - Show Value</title>

  <style>

    body {

      font-family: Arial, sans-serif;

      background: #f5f5f5;

      padding: 40px;

    }

    .container {

      width: 420px;

      margin: auto;

      background: #fff;

      padding: 20px;

      border-radius: 8px;

      box-shadow: 0 2px 8px rgba(0,0,0,.1);

    }

    .dropdown { position: relative; }

    .dropdown-btn {

      width: 100%;

      padding: 10px;

      border: 1px solid #ccc;

      border-radius: 6px;

      background: #fff;

      cursor: pointer;

      text-align: left;

    }

    .dropdown-menu {

      position: absolute;

      top: 45px;

      left: 0;

      width: 100%;

      background: #fff;

      border-radius: 8px;

      border: 1px solid #ddd;

      box-shadow: 0 4px 12px rgba(0,0,0,.15);

      padding: 12px;

      display: none;

      z-index: 10;

    }

    .dropdown-menu label {

      display: flex;

      align-items: center;

      margin-bottom: 8px;

      cursor: pointer;

    }

    .dropdown-menu input { margin-right: 8px; }

    .disabled { color: #aaa; cursor: not-allowed; }

    .selected-info {

      font-size: 13px;

      color: #666;

      margin-bottom: 8px;

    }

    .tags { margin-top: 12px; }

    .tag {

      display: inline-block;

      background: #ffe7d9;

      color: #ff6a00;

      padding: 4px 8px;

      border-radius: 6px;

      font-size: 13px;

      margin-right: 6px;

      margin-bottom: 6px;

    }

  </style>

</head>

<body>


<div class="container">

  <h3>Business Type</h3>


  <form method="POST" action="submit.php">


    <!-- INPUT GỬI BACKEND -->

    <input type="hidden" name="searchname" id="searchname">


    <div class="dropdown">

      <button type="button" class="dropdown-btn" id="dropdownBtn">

        Chọn loại hình kinh doanh

      </button>


      <div class="dropdown-menu" id="dropdownMenu">

        <div class="selected-info">

          Selected: <span id="count">0</span>/3

        </div>


        <label><input type="checkbox" value="Import and Export">Import and Export</label>

        <label><input type="checkbox" value="Retail & Agency">Retail & Agency</label>

        <label><input type="checkbox" value="Manufacturer">Manufacturer</label>

        <label><input type="checkbox" value="Wholesale">Wholesale</label>

        <label><input type="checkbox" value="Service Provider">Service Provider</label>

      </div>

    </div>


    <div class="tags" id="tags"></div>


    <button style="margin-top:15px;width:100%">Submit</button>

  </form>

</div>


<script>

  const dropdownBtn = document.getElementById("dropdownBtn");

  const dropdownMenu = document.getElementById("dropdownMenu");

  const checkboxes = dropdownMenu.querySelectorAll("input[type=checkbox]");

  const countEl = document.getElementById("count");

  const tagsEl = document.getElementById("tags");

  const hiddenInput = document.getElementById("searchname");

  const MAX = 3;

  const placeholder = "Chọn loại hình kinh doanh";


  dropdownBtn.onclick = () => {

    dropdownMenu.style.display =

      dropdownMenu.style.display === "block" ? "none" : "block";

  };


  document.addEventListener("click", e => {

    if (!e.target.closest(".dropdown")) {

      dropdownMenu.style.display = "none";

    }

  });


  checkboxes.forEach(cb => {

    cb.addEventListener("change", () => {

      const checked = [...checkboxes].filter(c => c.checked);

      if (checked.length > MAX) {

        cb.checked = false;

        return;

      }

      updateUI();

    });

  });


  function updateUI() {

    const checked = [...checkboxes].filter(c => c.checked);

    countEl.textContent = checked.length;


    // Disable khi đủ 3

    checkboxes.forEach(cb => {

      const label = cb.parentElement;

      if (!cb.checked && checked.length === MAX) {

        cb.disabled = true;

        label.classList.add("disabled");

      } else {

        cb.disabled = false;

        label.classList.remove("disabled");

      }

    });


    const values = checked.map(c => c.value);


    // 👉 HIỆN TRONG BUTTON

    dropdownBtn.textContent =

      values.length ? values.join(", ") : placeholder;


    // 👉 GỬI FORM

    hiddenInput.value = values.join(",");


    // // Tags

    // tagsEl.innerHTML = values

    //   .map(v => `<span class="tag">${v}</span>`)

    //   .join("");

  }

</script>


</body>

</html>


Thứ Ba, 9 tháng 3, 2021

HƯỚNG DẪN LẤY DỮ LIỆU TỪ NHIỀU CHECKBOX BẰNG AJAX /JQUERY VÀ PHP

Link: https://ttsvn.net/huong-dan-lay-du-lieu-tu-nhieu-checkbox-bang-ajax-jquery-va-php 

Ở bài hướng dẫn này , mình sẽ hướng dẫn các bạn cách lấy dữ liệu từ nhiều checkbox bằng ajax kết hợp với PHP. Nói thêm về Ajax, nó là một công nghệ được google sáng tạo ra dựa trên php và jQuery, là công nghệ lấy dữ liệu từ máy chủ mà không cần load lại trang web, cho phép chúng ta load cái mới mà không cần tải lại cái cũ sẽ đỡ mất thời gian hơn nên duyệt web sẽ nhanh hơn.

– Bước 1: Các cần phải tải thư viện jQuey.min.js , hoặc link trực tiếp như mình.

– Bước 2: Tạo một file index.php trong localhost với nội dung như sau:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>

<script>
jQuery(document).ready(function( ){
jQuery("input[name='checkbox[]']").click(function(){
var stringV = '';
// su dung vong lap de them gia tri checkbox vao chuoi....
jQuery("input[name='checkbox[]']:checked").each(function(){
stringV = stringV + ',' + jQuery(this).val();});
if(stringV.length > 1){
stringV = stringV.substring(1);
}
//ket thuc lap-----------&gt; su dung ajax gui den server.
//alert(stringV);
jQuery.ajax({
url:"xuly.php",
type:"post",
data:"id="+ stringV,
async: true,
success: function(result){
jQuery(".results").html(result);
}
})
})
});
</script>
<head>
<body>
<input type="checkbox" name="checkbox[]" id="1" value="1">
<input type="checkbox" name="checkbox[]" id="2" value="2">
<input type="checkbox" name="checkbox[]" id="3" value="3">
<input type="checkbox" name="checkbox[]" id="4" value="4">
<input type="checkbox" name="checkbox[]" id="5" value="5">
<input type="checkbox" name="checkbox[]" id="6" value="6">
<div class="results"></div> </body>
</html>

– Bước 3: Tạo một file xuly.php trong localhost với nội dung như sau:

<?php
$string= $_POST["id"]  ;
echo $string;
?>

 


Các bạn để ý : cặp thẻ này “<div class=”results”></div>” ở trong file index.php có tác dụng hiển thị giá trị trả về từ sever bằng cú pháp jQUery :

success: function(result){

jQuery(".results").html(result);

}

Thứ Ba, 10 tháng 12, 2019

checkbox css

**** Html:
<ul>
<li><input type='checkbox' name='checkbox'></li>
</ul>

**** Css:
input[name="checkbox"]{
    width: 1.3em;
    height: 1.3em;
    background-color: white;
    border-radius: 50%;
    vertical-align: middle;
    border: 1px solid #ddd;
    -webkit-appearance: none;
    outline: none;
    cursor: pointer;
}
.wpfFilterVerScroll::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 6px rgba(0,0,0,.3); 
    background-color: #737272; 
    border: 1px solid #000; 
}
.wpfFilterVerScroll::-webkit-scrollbar-track {
    border: 1px solid #000;
    padding: 2px 0;
    background-color: #404040;
}
.wpfFilterVerScroll{
    overflow-y: auto;
}
.wpfFilterVerScroll::-webkit-scrollbar {
    width: 10px;
}

Thứ Sáu, 5 tháng 4, 2019

checkbox javascript giới hạn

**** Javascript:

$("input[name=nhomnghe]").click(function() {
    var bol = $("input[name=nhomnghe]:checked").length > 4;
    $("input[name=nhomnghe]").not(":checked").attr("disabled",bol);
});

$("input[type=checkbox][class=nhomnghe]").click(function() {
   var bol = $("input[type=checkbox][class=nhomnghe]:checked").length >4;
   $("input[type=checkbox][class=nhomnghe]").not(":checked").attr("disabled",bol);
});

**** HTML:
<select name="nghanhnghe" class="form-control nhom_cha">
<option value="">Chọn nghành nghề</option>
<option value="1" selected="">An ninh, An toàn &amp; Bảo vệ</option>
<option value="2">Công Nghiệp</option>
</select>
r
<input type="checkbox" name="nhomnghe[]" value="10" class="nhomnghe">
<input type="checkbox" name="nhomnghe[]" value="20" class="nhomnghe">
<input type="checkbox" name="nhomnghe[]" value="30" class="nhomnghe">
<input type="checkbox" name="nhomnghe[]" value="40" class="nhomnghe">
<input type="checkbox" name="nhomnghe[]" value="50" class="nhomnghe">
<input type="checkbox" name="nhomnghe[]" value="60" class="nhomnghe">


Thứ Sáu, 25 tháng 3, 2016

nhập địa chỉ show map + checkbox lưu,show ra bên ngoài,lấy catid của muc_tintuc


## lấy catid của modules
$uil=new Uil();
$whe= $uil->getWhereCat("tintuc",1);

## save và show (input[type=checkbox])

+ show:
1---------------
$khacbiet = explode(",",$data_2['Khac']); // lấy database xuống field:khac

if(in_array("Phòng khách",$khacbiet)){
echo"yes";
- Nếu có phòng khác thì show ra --->yes
}
2-----------------
$os = explode(",",$data['tool']);
$sql = "SELECT * FROM res_tool WHERE lang_id=1";
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result)){
$id=$row['id'];
if(in_array($id, $os))
<td>".$row['name']."&nbsp;<img src=\"".$site_live."themes/"._THEME_NAME."/images/check.gif\" class='detail-resrealest-pic'></td>
else
<td>".$row['name']."</td>

if($j%4==0)
</tr><tr>
$j++;
}

+ trình diễn

<input type="checkbox" value="Phòng ngủ" name="other[]">
<input type="checkbox" value="Phòng khách" name="other[]">
<input type="checkbox" value="Bếp" name="other[]">

+ Lưu vào database

if($_POST['other']!=""){
$xother = implode(",",$_POST['other']);
}


## nhập địa chỉ vào fields ra ngoài show map đúng vị trí tên nhập

include("../classess/EasyGoogleMap.class.php");

<input class="sition-map" type="textbox" name="map">

if($data['map']){

$gm = & new EasyGoogleMap("ABQIAAAAyc62EJMO4347R0R7Y-hIoRRm9JLgkT58VziY1WRFxi4k-WwfYxRVu4xKP3r3LO91JI9uGpEkLrqDBg");
$gm->SetMarkerIconStyle('STAR');
$gm->SetMapZoom(15);
$gm->SetAddress("".$data['map']." ,VIET NAM");
$gm->SetInfoWindowText($data['map']);

echo "<center>".$gm->GmapsKey().$gm->MapHolder().$gm->InitJs().$gm->UnloadMap()."</center>";
}

--> download: tại đây

Thứ Năm, 27 tháng 2, 2014

checkbox ajax load data

 Application ajax
<script type="text/javascript">
    $(document).ready(function(){
        $('.act_box').change(function(event){           
            checked_value = $(this).val();  // giá trị form nhập vào          
            checked_id = $(this).attr("data_id"); // giá trị atributte gán vào
           $.ajax({
                url: 'admin.php',
                type: 'post',
                dataType: 'html',
                data: {op:"do_ajax",feed_id: checked_value,data_id:checked_id},
            })
            .done(function(data) {
                console.log("success"+data);
            })
            .fail(function() {
                console.log("error");
            })
            .always(function() {
                console.log("complete");
            });              
                   
        });   
    });
</script>

Application html
<input id="cb1" class="act_box" type="checkbox" value="1" checked="checked" data_id="720">


Application do_ajax - php 

$gid = $_POST['feed_id'];        ======> form nhập giá trị
$data_id = $_POST['data_id']; ======> 720

download:tại đây



Thứ Năm, 10 tháng 10, 2013

checkbox giới hạn khi click


example : limit >= 4 

<script type="text/javascript">
    $(document).ready(function() {
 #### name          
            $("input[type=checkbox][
name=sender_sex]").click(function() {       
            var bol = $("input[type=checkbox][
name=sender_sex]:checked").length >= 4;    
            $("input[type=checkbox][
name=sender_sex]").not(":checked").attr("disabled",bol);       
            }); 

  ####  class        
            $("input[type=checkbox][class=sender_sex]").click(function() {       
            var bol = $("input[type=checkbox][
class=sender_sex]:checked").length >= 4;    
            $("input[type=checkbox][
class=sender_sex]").not(":checked").attr("disabled",bol);       
            });

    });

  </script> 
 <body>
         <input type="checkbox" name="sender_sex" class="sender_sex" value="">
</body>