OnChange Event when Edit Forms
How to create onchange event when user edit on text box, ex: textbox A + textbox B = textbox C. So the value on textbox C is automatically filled when A or B changed. Thank's
How to create onchange event when user edit on text box, ex: textbox A + textbox B = textbox C. So the value on textbox C is automatically filled when A or B changed. Thank's
Simply put the following code under: "Client Scripts" -> "Table-Specific" -> "Edit Page" -> "Startup Script":
$("#x_A").on('change keyup paste mouseup', function() {
$("#x_C").val($("#x_A").val() + $("#x_B").val());
});
$("#x_B").on('change keyup paste mouseup', function() {
$("#x_C").val($("#x_A").val() + $("#x_B").val());
});
Thank you Mobhar, I've tried your code, but nothing happen on textbox C, sorry I'm newbie in web programming. Am i missed something? Do I have to put equal sign after val C?
If the name of your fields are "A", "B", and "C" respectively, then PHPMaker will generate the ID of the textbox become: "x_A", "x_B", and "x_C".
So, make sure you have inspected the ID of textboxes, and they are the same with that above.
It's working now, I missed the check mark on Edit Page, previously i put it on the inline edit. Now it's working but the result is not exactly I want, I want the value on textbox C is sum of the A and B. Ex: A=2, B=3 so the value of C=5, but now the value of C is 23. Please how to fix this?
Use javascript parseInt() function to convert the string to integer before your add:
var a = $("#x_A").val();
a = parseInt(a);
var b = $("#x_B").val();
b = parseInt(b);
Then,
$("#x_C").val(a+ b);
it's working as expected now, after change the code from Mobhar :
$("#x_A").on('change keyup paste mouseup', function() {
$("#x_C").val(+$("#x_A").val() + +$("#x_B").val());
});
$("#x_B").on('change keyup paste mouseup', function() {
$("#x_C").val(+$("#x_A").val() + +$("#x_B").val());
});
Thank you.
if field A is a float tye and field B is a integer.
can it calculate due to this code??
i' tried but it don't work
The code will work. Post your modified code for discussion.
my field "sell" is a auto fill value (float type)
and field "amount" is for user to type in (integer type)
field "sumcost" is a result: (float type)
so my code is
$("#x_amount").on('change keyup paste mouseup', function() {
$("#x_sumcost").val(+$("#x_sell").val() * +$("#x_amount").val());
});
i put in in client script -> table-specific ->add/copy paste -->startup script
so do in the edit page too.
but when i run it don't matter. what wrong with it??
Are you sure the "sell" field has already had the correct value? If you change the multiply (*) sign with plus (+) sign, doesn't it work, too?