Solved

jQuery change totals when many form textboxes are changed

Posted on 2012-03-30
11
237 Views
Last Modified: 2012-04-20
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 );
0
Comment
Question by:nanharbison
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37789319
You need unique IDs

Why not use class or name?
0
 
LVL 17

Author Comment

by:nanharbison
ID: 37789582
Each textbox has a unique ID. How do I use a class or name?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37789983
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/
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 17

Author Comment

by:nanharbison
ID: 37791813
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37792502
You need UNIQUE ids for all elements on a page
0
 
LVL 17

Author Comment

by:nanharbison
ID: 37808839
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37809414
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
0
 
LVL 17

Author Comment

by:nanharbison
ID: 37832815
Where do you look in firebug to see there are IDs that are not unique?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37832843
Apologies. Perhaps I saw

edit-submitted-users-desktop-users-wrapper
and
edit-submitted-users-desktop-users
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37832855
So the selector could be

$("input[name|='submitted[users]']")

http://api.jquery.com/attribute-contains-prefix-selector/
0
 
LVL 17

Author Closing Comment

by:nanharbison
ID: 37873401
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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now