Link to home
Start Free TrialLog in
Avatar of nanharbison
nanharbisonFlag for United States of America

asked on

jQuery change totals when many form textboxes are changed

I have about 25 textboxes where users enter how many of each component they want, and the text box which holds the total should change on the fly.   Is there a way to check ALL of the textboxes for changes as they happen instead of writing out each one?
This is here:
http://www.cloudconnect.net/pricing-estimate
I thought this was working, but it is not, so I can't get to work either. It works in Firebug though, so I don't understand why it doesn't work on the page

function recalculateTotal() {
    var count = $('#edit-submitted-users-desktop-users').val();
    count = parseFloat( count );
    $('#edit-submitted-users-total-users-price').val( count * p1 );
}
var fieldCount = $('#edit-submitted-users-desktop-users');
fieldCount.change( recalculateTotal );
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

You need unique IDs

Why not use class or name?
Avatar of nanharbison

ASKER

Each textbox has a unique ID. How do I use a class or name?
Not on the page I looked at. There were at least two fields with the same ID and your code here obviously try to get at more than one field using one ID

Please have a look here

http://api.jquery.com/attribute-starts-with-selector/
I have set up the form with with field sets, so those are the same for groups of textboxes, but the input textboxes are all different.
You need UNIQUE ids for all elements on a page
Ugh, this is a Drupal site, and the module created these non-unique IDs, and I have no control over that. Is this why the javascript isn't working? it works perfectly when I run it in Firebug.
How come you have no control? Can't you edit the Drupal templates?
And what do you mean "it works in firebug" I used firebug to see you did not have unique ids
Where do you look in firebug to see there are IDs that are not unique?
Apologies. Perhaps I saw

edit-submitted-users-desktop-users-wrapper
and
edit-submitted-users-desktop-users
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did the code for this question on my own, by brute force. It isn't elegant at all, but it works. But I appreciate the time mplungjan put in to look at what I was doing.