I have input type checkbox in html looks like this:
<?php
$result = $db->get_results("SELECT * FROM site_gst where description='YES'");
foreach ((Array) $result as $r){ ?>
<input type="checkbox" name="line_description2[]" id="line_description2_1"
required value="<?php echo $r->description ?>|<?php echo $r->is_gst_applicable ?>"
checked><?php echo $r->description;?>
<?php } ?>
In the form, the checkbox is always checked. If the user uncheck, it will perform calculation. If the checkbox remain checked, it also perform a calculation. Here is my JQuery that i get so far :
jQuery(document).on("change", "[id^='line_description2_']", function() {
var line_desc_id = jQuery(this).attr("id");
var split_id = line_desc_id.split("_"); // id has value line_description_x. so value of x is at index 2
var line_desc_val = jQuery(this).val();
var split_val = line_desc_val.split("|");
if ($(this).is(':checked')) {
jQuery("#line_gstflag_"+split_id[2]).val("1");
}
else {
jQuery("#line_gstflag_"+split_id[2]).val("0");
}
If Im using this JQuery, the problem is, the user need to uncheck 1st, then checked again the checkbox to perform a calculation which is do this statement jQuery("#line_gstflag_"+split_id[2]).val("1"); and then if the user want to perform the other calculation, it need to uncheck back. I want it perform its calculation which is do this statement jQuery("#line_gstflag_"+split_id[2]).val("1"); without uncheck, then checked back. The user need to unchecked 1st then checked back to perform this statement. thats the problem. Thanks In Advance.
Aucun commentaire:
Enregistrer un commentaire