admin管理员组文章数量:1302382
I have 4 checkboxes. All in form of;
input type="checkbox" name="Group[]" id="Group" value="uniquevalue"
I have 3 of 4 of them checked. How can I send the values that are checked in the form
"a = chkedvalue1 &b = chkedvalue2 &c = chkedvalue3"
?
I'm using jquery 1.4.2
Thank you! Spent a whole day with this issue to no avail.
I have 4 checkboxes. All in form of;
input type="checkbox" name="Group[]" id="Group" value="uniquevalue"
I have 3 of 4 of them checked. How can I send the values that are checked in the form
"a = chkedvalue1 &b = chkedvalue2 &c = chkedvalue3"
?
I'm using jquery 1.4.2
Thank you! Spent a whole day with this issue to no avail.
Share edited Dec 23, 2010 at 11:53 Haim Evgi 126k46 gold badges222 silver badges226 bronze badges asked Dec 23, 2010 at 11:51 DariusDarius 111 silver badge2 bronze badges 1-
1
Don't. Really. Have the server side process expect
Group[]=chkedvalue1&Group[]=chkedvalue2&Group[]=chkedvalue3
(which is how the form data will be encoded using a normal forum submission (this way you can build on things that work)) and then just use jQuery'sserialize()
– Quentin Commented Dec 23, 2010 at 11:54
3 Answers
Reset to default 4First, remove that id
attribute, it needs to be unique. Then to get the array of values you can just .serialize()
the <form>
like this:
var data = $("form").serialize();
Note this will produce Group[]=...
, remove the []
from the name
attributes if you just want Group=
for each.
...or if you want the array of values, use .map()
, like this:
var arr = $("input[name='Group[]']:checked").map(function() {
return this.value;
}).get();
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test",$con);
$ID = $_GET['id'];
$sql = "select city_name from city where id='$id'";
$fetch = mysql_fetch_array(mysql_query($sql));
$result = explode(",",$fetch['city_name']);
?>
<html>
<body>
<form method="post" >
<input type="checkbox" name="city[]" value="Faridabad" <?php for($i=0;$i<4;$i++) if($result[$i]=='Faridabad')echo 'checked'; ?> />Faridabad
<input type="checkbox" name="city[]" value="Gurgaon" <?php for($i=0;$i<4;$i++) `if($result[$i]=='Gurgaon') echo 'checked';?>/>Gurgaon`
<input type="checkbox" name="city[]" value="Noida"<?php for($i=0;$i<4;$i++) if($result[$i]=='Noida') echo 'checked'; ?>/>Noida
<input type="checkbox" name="city[]" value="Gaziabad" <?php for($i=0;$i<4;$i++) if($result[$i]=='Gaziabad') echo 'checked'; ?>/>Gaziabad
</form>
</body>
</html>
I suggest you serialize the form.
本文标签: phpHow do I get multiple checkbox values and send the values via ajax in jqueryStack Overflow
版权声明:本文标题:php - How do I get multiple checkbox values and send the values via ajax in jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741708947a2393725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论