Aristain Aristain - 7 months ago 19
PHP Question

Checkbox value doesnt show when a customer is clicked

I am echoing to my website possible checkbox values that are in a table JobChoose like this

<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
$checkbox .= '<li><input type="checkbox" id="Jobselect" name="Job" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?>

<?php echo $checkbox;?>


When a checkbox is selected is inserted to a customer info.
But when i am trying to to get selected value back nothing appears when i click to a customer although it appears in mysql database

echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";

<script type='text/javascript'>
$('#tabled').on('click', 'tr', function () {
$("#Jobselect").val($(this).find("td").eq(19).html());
});
</script>


Also i fetch search results into a table like this


$sql = "SELECT * FROM new_record WHERE surname LIKE
'%".$_POST["search"]."%' or name LIKE'%".$_POST["search"]."%' or
barcode LIKE'%".$_POST["search"]."%'"; $result =
mysqli_query($connect, $sql); if(mysqli_num_rows($result) > 0) {

while($row = $result->fetch_assoc()){

echo "<tr>";
echo "<td >". $row["id"] ."</td>";
echo "<td>". $row["surname"] ."</td>";
echo "<td>". $row["name"] ."</td>";
echo "<td>". $row["company_name"] ."</td>";
echo "<td>". $row["firm"] ."</td>";
echo "<td>". $row["address"] ."</td>";
echo "<td>". $row["town"] ."</td>";
echo "<td>". $row["tk"] ."</td>";
echo "<td>". $row["country"] ."</td>";
echo "<td>". $row["telephone"] ."</td>";
echo "<td>". $row["fax"] ."</td>";
echo "<td>". $row["mobile"] ."</td>";
echo "<td>". $row["mail"] ."</td>";
echo "<td>". $row["web_site"] ."</td>";
echo "<td>". $row["barcode"] ."</td>";
echo "<td>". $row["visitors"] ."</td>";
echo "<td align='center' class='hidden'>". $row["custId"] ."</td>";
echo "<td align='center' class='hidden'>". $row["trn_date"] ."</td>"; echo "<td align='center' class='hidden'>".


$row["HowToFindUs"] .""; echo "". $row["Job"] ."";
echo "";
} } else {

echo 'Data Not Found'; } ?>

Answer

To get selected checkbox value you should try below code :

<?php
$got = mysql_query("SELECT * FROM JobChoose");
$checkbox = '';
while ($row = mysql_fetch_assoc($got)) {
    $checkbox .= '<li><input type="checkbox" name="Job[]" value = "' . $row['Job'] . '">' . $row['Job'] . '</input></li>';
} ?> 

<?php echo $checkbox;?> 

Here in your case you have place id for all checkboxes are same which was not correct.

Also in JS you should try below code :

echo "<td align='center' class='hidden'>". $row["Job"] ."</td>";

    <script type='text/javascript'>
        $('input[type=checkbox]').click(function () {
            if($(this).is(':checked')) {
                alert($(this).val());
            }
        });
    </script>

Please try this.

Comments