[英]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.