How To Put Value of many field in one checkbox?
I have a problem. I made a program which is need to show many row of database and in every row must have a check box to check the item. At the same time, i have to update database if the checkbox was checked. to update it, i need 2 field value to be parse along with the checkbox. How should i put the value of the field?
HTML:
<!-- <input name="cek" <?php echo $row['STATUS_KIRIM']; echo $row['ID_NOTA_JUAL'];
echo $row['ID_BARANG'];?> id="cek<?php echo $row['STATUS_KIRIM'];?>"
type="checkbox" value="<?php echo $row['STATUS_KIRIM'];?>" <?php if ($row['STATUS_KIRIM'] == 1)
echo 'checked="checked"'; else 'checked="unchecked"';?>
/> -->
JS :
<script type="text/javascript">
$("#cek").click(function()
{
$("input").val(["$row['STATUS_KIRIM']", "$row['ID_NOTA_JUAL']", "$row['ID_BARANG']"]);
$.post("cek.php",$("input"), proses);
function proses(val[0])
{
if (val[0]=='1')
{
alert("Checked the item");
}
else
{
alert("Unchecked the item");
}
}
return false;
});
});
</script>
// cek.php
include "include/ConnDB.php";
include "include/function.php";
$idp = $_POST($row['ID_NOTA_JUAL']);
$idb 开发者_开发问答= $_POST($row['ID_BARANG']);
$status = $_POST($row['STATUS_KIRIM']);
$db = new OraSQL();
$db2 = new OraSQL();
if($status == 1)
{
$db->execute("UPDATE T_ITEM SET STATUS_KIRIM=1 WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
} else {
$db->execute("UPDATE T_ITEM SET STATUS_KIRIM=0 WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
}
$query2 = sprintf("SELECT STATUS_KIRIM FROM T_ITEM WHERE ID_NOTA_JUAL='".$idp."' AND ID_BARANG='".$idb."'");
$result2 = $db2->query($query2);
$row2 = $result2->fetch_assoc();
if(isset($row2['STATUS_KIRIM'])) $cek=$row2['STATUS_KIRIM']; else $cek="";
echo $cek ;
?>
Use <input type="hidden"/>
for the extra values. You will have to give them some name that you can easily find, but that will be the simplest solution. You could also use stringified JSON for the checkbox value if you'd prefer, but then you'll have to handle the JSON reading/writing as well.
精彩评论