php - jquery check box some ideas -
im trying make checkbox disable computation in query here
form code:
<input type="hidden" name="stud_no[]" value="<?php echo $row['student_no'];?>"> <input type="text" name="prelim[]" value="<?php echo $row['prelim_pts']?>" id="prelim_<?php echo $row['student_no'];?>" class="txtprelim" ></td> <td><input type="text" name="midterm[]" value="<?php echo $row['midterm_pts']?>" id="midterm_<?php echo $row['student_no'];?>" class="txtmidterm" ></td> <td> <input type="text" name="final[]" value="<?php echo $row['finals_pts']?>" id="final_<?php echo $row['student_no'];?>" class="txtfinal" ></td> <td> <input type="text" name="average[]" id="average_<?php echo $row['student_no']; ?>" value="<?php echo $row['average_pts']; ?>" readonly="readonly"> </td> <td><input type="checkbox" name="disable[]" value="<?php echo $row['disable_comp'];?>" class="dis"> </td>
here jquery code:
$(document).ready(function(){ p=""; m=""; f=""; $(".txtprelim").keyup(function(){ var id = $(this).attr("id").replace("prelim_",""); p = $("#prelim_" + id).val(); m = $("#midterm_" + id).val(); f = $("#final_" + id).val(); compute( p,m,f, id); //alert($(".txtprelim").val()); }); $(".txtmidterm").keyup(function(){ var id=$(this).attr("id").replace("midterm_",""); p = $("#prelim_" + id).val(); m = $("#midterm_" + id).val(); f = $("#final_" + id).val(); compute( p, m, f,id); //alert($(".txtmidterm").val()); }); $(".txtfinal").keyup(function(){ var id=$(this).attr("id").replace("final_",""); p = $("#prelim_" + id).val(); m = $("#midterm_" + id).val(); f = $("#final_" + id).val(); compute( p, m, f, id); //alert($(".txtfinal").val()); //alert($("f").val()); }); function compute(p , m , f , studno){ // alert("p="+p+" m="+m+" f="+f); var average=""; average = parsefloat(p * 0.3) + parsefloat(m * 0.3 )+ parsefloat(f * 0.4); $("#average_" + studno).val(average.tofixed()); //alert(average); } $("input[type='dis']").change ( function(){ var val =$(this).val(); if($(this).is(':checked')) { alert($(this).val()); } }); });
so understood code should work better. in last function there no type='dis'
. that's class
$(document).ready(function() { p = ""; m = ""; f = ""; var computevalues = function(){ var id = $(this).attr("id").replace("prelim_", "").replace("midterm_", "").replace("final_", ""); p = $("#prelim_" + id).val(); m = $("#midterm_" + id).val(); f = $("#final_" + id).val(); compute(p, m, f, id); }; $("input").bind('keyup', computevalues); function compute(p, m, f, studno) { var average; average = parsefloat(p * 0.3) + parsefloat(m * 0.3) + parsefloat(f * 0.4); $("#average_" + studno).val(average.tofixed()); } $(".dis").change(function() { var val = $(this).val(); if ($(this).is(':checked')) { $("input").unbind('keyup', computevalues); } else { $("input").bind('keyup', computevalues).trigger('keyup'); } }); });
and fiddle test http://jsfiddle.net/spokey/nhcst/
updatde:
you can add <input type="hidden" id="changeme" value="0">
in form , when user selects checkbox
value of hidden input
change 1
$(".dis").change(function() { var val = $(this).val(); if ($(this).is(':checked')) { $("input").unbind('keyup', computevalues); $("#changeme").val('1'); } else { $("input").bind('keyup', computevalues).trigger('keyup'); $("#changeme").val('0'); } });
Comments
Post a Comment