In php : use checkbox in foreach loop
<?php foreach ($products as $product) { ?>
<tr>
<td class ="left"><input type="checkbox" name="checkbox[]" id="checkbox" value="<?php echo $product['model']; ?>" /></td>
<?php }?>
click the button to call the function:-
<div class="buttons"><a class="button" onclick="chkbox_value()"><?php echo "delivery challan"; ?></a></div>
javascript function:-
<script type="text/javascript">
function chkbox_value()
{
var order_id=document.getElementById("order_id").value;
alert(order_id);
var x = document.getElementById("checkbox").value;
//alert(x);
vals = "";
cLen = document.getElementsByName("checkbox[]").length;
for (i=0; i<cLen; i++) {
if (document.getElementsByName("checkbox[]")[i].checked) {
if (i < cLen) {
vals += document.getElementsByName("checkbox[]")[i].value + ",";
} else {
vals += document.getElementsByName("checkbox[]")[i].value;
}
}
}
//alert(vals);
window.location.href="view/template/sale/delivery_challan.php?order_id="+order_id+"&value="+vals;
}
</script>
(tested codes)
No comments:
Post a Comment