i have this code:
<?php
$result = mysqli_query($con,"SELECT * FROM table");
while($row = mysqli_fetch_array($result)){
echo "<input type=\"checkbox\" id=\"$row[use_id]\" name=\"things[]\" value='$row[col_id]' >$row[col]<br>";
echo "<input placeholder=\"description\" type=\"text\" name=\"ans1\" class='$row[col_id]' id=\"answer1\" style='display:none;'>";
echo "<align='left'><input placeholder=\"source\" type=\"text\" name=\"ans2\" class='$row[use_id]' id=\"answer2\" style='display:none;'>";
}
?>
using this script:
<script>
$(document).ready(function(){
$("input[type=checkbox]").change(function(){
var divId = $(this).attr("id");
if ($(this).is(":checked")){
$("." + divId).show();
}
else{
$("." + divId).hide();
}
});
});
</script>
and i want to take the data from the 2 textboxes using ths code:
$checkBox = $_POST['things'];
for($i=0; $i<sizeof($checkBox); $i++){
$qs = "INSERT INTO sccm_reherb.table2 values('$_POST[id]','".$checkBox[$i]."','$_POST[ans1]','$_POST[ans2]')";
echo $qs;
mysqli_query($con,$qs) or die(mysqli_error($con));
}
but '$_POST[ans1]' and '$_POST[ans2]' are always empty..can anyone help me? thanks in advance!