Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery change totals when many form textboxes are changed

Posted on 2012-03-30
11
238 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch FIle delete files with particular date 10 98
view results of google SQL query 9 66
Using a variable to name output in powershell script 2 41
BATCH to EXE Converter 2 39
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

829 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