Friday, 15 April 2011

javascript - calculating value of cookie using jquery -



javascript - calculating value of cookie using jquery -

there 2 textboxes , user input value , store in java script variable after have persist value storing value in > blockquote cookies, 1 time again when user input new value want add-on of value lastly value

if understand question correctly seek append new value lastly value on same cookie?

if i'm right first of seek utilize plugin simplify handling of cookies.

https://github.com/carhartl/jquery-cookie

then seek this:

$("#yourinput").on("change", function() { var actualval = parseint($(this).val(), 10); var yourcookie = $.cookie('yourcookie') if( yourcookie ) { var newval = parseint(yourcookie, 10) + actualval; $.cookie('yourcookie', newval); } else { $.cookie('yourcookie', actualval); } });

edit based in code, seek parseint radix integer value. if have float value, seek parsefloat on inputs.

$(document).ready(function () { $('.ok').click(function () { var v_qty = parseint($('.qty').val(), 10); var v_hrs = parseint($('.hrs').val(), 10); var loadwatt = parseint($('.loadwatt').val(), 10); var total = 0; var check = 0; $.cookie('b_total'); check = $.cookie('b_total'); var count = parseint($.cookie('b_total'), 10); alert(count); var total = (v_qty * loadwatt) * v_hrs; total = parseint(total, 10) + count; var date = new date(); var minutes = 1; date.settime(date.gettime() + (minutes * 60 * 1000)); $.cookie("b_total", total, { expires: date }); check = $.cookie('b_total'); alert(check); }); });

javascript php jquery

No comments:

Post a Comment