Solved

jQuery change totals when many form textboxes are changed

Posted on 2012-03-30
11
235 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
Comment Utility
You need unique IDs

Why not use class or name?
0
 
LVL 17

Author Comment

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

Expert Comment

by:Michel Plungjan
Comment Utility
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
 
LVL 17

Author Comment

by:nanharbison
Comment Utility
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
Comment Utility
You need UNIQUE ids for all elements on a page
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Author Comment

by:nanharbison
Comment Utility
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
Comment Utility
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
Comment Utility
Where do you look in firebug to see there are IDs that are not unique?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This article will show, step by step, how to integrate R code into a R Sweave document
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

21 Experts available now in Live!

Get 1:1 Help Now