简体   繁体   English

当选中复选框时,我想通过jquery将其值发送到其他PHP文件

[英]When a checkbox is checked i want to send its value to other PHP file through jquery

Actually i want to send the value of checkbox when it is checked through jquery...means when i click on checkbox it has to send automatically...i tried with following code.. 实际上我想通过jquery检查复选框的值...当我点击复选框时它必须自动发送...我尝试使用以下代码..

$(document).ready(function () {
    $(".checkBox").change(function () {
        var s = $(this).val();
        var dataString = 's=' + s;
        $.ajax({
            type: "GET",
            url: "xyz.php",
            data: dataString,
            cache: false,
            success: function (html) {}
        });
    });
});

and html code is 和HTML代码是

<div class = "checkBox">
<input type = "checkbox" name = "select[]" value = <?php $friendUid?> />
</div>

I was unable to send to other page 我无法发送到其他页面

Change your html: Put the class = "checkBox" onto the checkbox element 更改你的html:把class = "checkBox"放到checkbox元素上

<div>
<input type = "checkbox" name = "select[]" value = <?php $friendUid?>  class = "checkBox"/>
</div>

选择器$(“。checkBox”)会将该函数附加到具有checkBox类的任何项目,并且由于您的复选框没有将其作为其类,因此您实际上将函数附加到包含复选框的div,当然永远不会触发你的功能。

<?php $friendUid?>应该是<?php echo $friendUid ?>

with $(".checkbox") you're referencing something of class 'checkbox' (ie, your div, not the actual checkbox). 使用$(“。checkbox”)你引用了一些类'复选框'(即你的div,而不是实际的复选框)。 Add the class to the <input type='checkbox'> instead 将类添加到<input type='checkbox'>

try this in your code and let us know what happens. 在您的代码中尝试这一点,让我们知道会发生什么。

<script type="text/javascript">
   alert('check0');
   $(document).ready(function () {
      alert('check1');
      $(".checkBox").change(function () {
         alert('check2');
         var s = $(this).val();
         var dataString = 's=' + s;
         $.ajax({
            type: "GET",
            url: "test.php",
            data: dataString,
            cache: false,
            success: function (html) {
               alert('check3');
            }
         });
      });
   });
</script>

<input type="checkbox" class="checkBox" />

暂无
暂无

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

相关问题 我希望在选中任何其他复选框时自动选中第一个复选框 - I want the first checkbox to be autochecked when any of the other checkox are checked (PHP / JQuery?)选中复选框时获取表的行值 - ( PHP /JQuery?) Get the table row value when the checkbox is checked 单击删除按钮后,我想获取ID,但是我无法在其他页面(PHP)中发送其值 - I want to get id once delete button got clicked, I am unable to send its value in other page, php 当我提交表单输入类型=文件以使用 php 发送图像时,我想重定向到另一个页面 - when i submit form input type=file for send image with php i want redirect to an other page 仅当仅通过 php 选中复选框时,如何显示表单的其他输入字段 - How to show other input fields of form only when checkbox is checked through php only 复选框未检查时未返回值PHP Codeigniter - Checkbox not returning value when not checked PHP Codeigniter 当值与PHP匹配时,将复选框显示为选中状态 - Show checkbox as checked when value matches php 如果在 html 表中选中复选框,那么我想在按下更新按钮时更新该行的值 - if checkbox is checked in html table then i want to update the value of that row when update button is pressed 记住复选框值,如果其检查的数组名称采用php形式 - remember checkbox value if its checked array name in a form php 如何通过PHP MVC使用Ajax jQuery Post发送复选框数组和其他一些值 - How to send an checkbox array and some other values with ajax jquery post through PHP MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM