Update fields Jquery

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
japeth
Forum Newbie
Posts: 12
Joined: Fri Feb 08, 2013 2:21 am

Update fields Jquery

Post by japeth »

Hi,

I'm trying to update my fields once I perform changing values from other fields.
please see my fields.

textfield1 = 100 <--____VALUES---
textfield2 = 100 <--____VALUES---
textfieldTotal = 200 <--___ Total ( Need to change this fields every time i perform simple addition to my textfield1 and textfield2.

Any good tutorial? I know it can be done in Jquery.

thank you.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Update fields Jquery

Post by Christopher »

Register the change event for textfield1 and textfield2. In the function you register update the value of textfieldTotal from the values of textfield1 and textfield2.

There are docs and examples here: http://api.jquery.com/change/
(#10850)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Update fields Jquery

Post by pickle »

When you do make some headway, post your code here, because people new to jQuery rarely use it as efficiently as they could be, we might be able to give you some further pointers.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
japeth
Forum Newbie
Posts: 12
Joined: Fri Feb 08, 2013 2:21 am

Re: Update fields Jquery

Post by japeth »

Hi,

Can somebody help me to solve this problem?

I have form, form contains these fields.

Principal - textfield1
Interest - textfield2
Service Charge - textfield3
and Total. - textfield4

scenario is this.
I will input an amount of (2000.00) in Principal(textfield1) , automatically the Total(textfield4) will change from 0.00 to 2000.00, and when I input 12 in Interest(textfield2) the total will update again to 2240.00 same with service charge. if i input 100 in service charge(textfield3) it will total to 2340.00.

All best.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Update fields Jquery

Post by requinix »

You've been given help already. Scroll up. So what progress have you made so far?
japeth
Forum Newbie
Posts: 12
Joined: Fri Feb 08, 2013 2:21 am

Re: Update fields Jquery

Post by japeth »

Here's,

but I want the text total to automatically change everytime i change the value in textfields without going to other field.

Code: Select all

$(document.body).on('change', 'input[name]', function() {
    var form = document.forms['calculator'],
        prin = parseFloat(form.principal.value),
        intr = parseFloat(1 + form.interest.value),
        serv = parseFloat(form.service.value);

    $('[name=total]').val(prin * intr + serv);  
});

$(function () {
    // manually trigger the change event to display
    // the total using the default values
    $(document.forms['calculator'].principal).change();
})
thanks,

s.dot| - Moderator Edit - Please use the formatting tags when posting code.
rejsertil
Forum Newbie
Posts: 1
Joined: Thu Jun 06, 2013 5:41 am

Update fields Jquery

Post by rejsertil »

The input element has lost focus jquery input field change even when value is changed via jquery . when jQuery itself tries to change the elements but not when the elements gets changed from outside jQuery .
Post Reply