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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Answers
    3931
    Vote Rating
    1271
      0  

    Default

    Please stop just blindly throwing code in. You have to define the form variable which equals btn.up('formpanel');
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Answers
    3931
    Vote Rating
    1271
      0  

    Default

    There was a typo... instead of numberfields it should be numberfield.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    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
  •