php - checkbox values not passed through JSON -
it working fine. i'm surprise find of sudden, checkbox values not passed through in $_post via json. can't seem understand why. me this.below checkbox in php.
$subjects_id= $row['subid']; <td><input type="checkbox" name="sub['.$subjects_id.']" id="sub" value=""> </td>';
json
$("document").ready(function(){ $(".form").submit(function(){ var data = { "action": "test" }; data = $(this).serialize() + "&" + $.param(data); $.ajax({ type: "post", datatype: "json", url: "response.php", //relative or absolute path response.php file data: data, success: function(data) { $(".the-return").html( "favorite beverage: " + data["favorite_beverage"] + "<br />favorite restaurant: " + data["favorite_restaurant"] + "<br />gender: " + data["gender"] + "<br />json: " + data["json"] ); alert("form submitted successfully.\nreturned json: " + data["json"]); } }); return false; }); });
i'm sure there's no problem json. doubt on php checkbox. in json key-value pairs, checkbox not passed although it's checked!
edit::
in troubleshooting, found below set of checkboxes conflicting above..so when present above checkboxes values not collected.when comment out these, above checkboxes' values collected!
<table class="small-12 medium-12 large-6 large-centered columns" class="availability"> <tr> <th></th><th>weekdays</th><th>weekends</th> </tr> <tr> <td class="text-right">morning<br/>(8am-12m)</td> <td> <div class="switch demo3"> <input type="checkbox" name="m_week" id="m_week"> <label><i></i></label> </div> </td> <td> <div class="switch demo3"> <input type="checkbox" name="m_end" id="m_end"> <label><i></i></label> </div> </td> </tr> <tr> <td class="text-right">afternoon<br/>(12am-6m)</td> <td> <div class="switch demo3"> <input type="checkbox" name="a_week" id="a_week"> <label><i></i></label> </div> </td> <td> <div class="switch demo3"> <input type="checkbox" name="a_end" id="a_end"> <label><i></i></label> </div> </td> </tr> <tr> <td class="text-right">evening<br/>(6am-10m)</td> <td> <div class="switch demo3"> <input type="checkbox" name="e_week" id="e_week"> <label><i></i></label> </div> </td> <td> <div class="switch demo3"> <input type="checkbox" name="e_end" id="e_end"> <label><i></i></label> </div> </td> </tr> </table>
your checkboxes sending true if checked, nothing if unchecked. can correct using :
$('checkbox').each(function(){ $(this).val( checkbox[0].checked ? "true" : "false" ); });
checkbox.
this set value of checkbox "true" or "false" (value property string).
Comments
Post a Comment