Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: How do I do a simple calculation with the input from a form field?

  1. #11
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Answers
    3976
    Vote Rating
    1389
      0  

    Default

    Please stop just blindly throwing code in. You have to define the form variable which equals btn.up('formpanel');
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  2. #12
    Sencha User
    Join Date
    Jan 2012
    Posts
    63
    Vote Rating
    0
      0  

    Default

    For what it is worth, the for loop didn't work here.

    i.e. all of this..did NOT work - for whatever reason... 'fields.length' kept returning '0':

    Code:
    var fields = form.query('numberfields'),
    f = 0,
    fNum = fields.length,
    sum = 0;
    
    for (; f < fNum; f++) {
    sum += fields[f].getValue();
    }
    However, what DID work though was form.getValues();

    i.e. this snippet:

    Code:
    handler: function(btn) {
       form = btn.up('formpanel');
       var values = form.getValues();
       sum = (values.Num1 + values.Num2 + values.Num3 + values.Num4);
    So maybe you might want to update the 'accepted answer' for this question.

    Thanks!

  3. #13
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Answers
    3976
    Vote Rating
    1389
      0  

    Default

    There was a typo... instead of numberfields it should be numberfield.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •