?
Solved

Automatically adjust numbers in input fields to match max value

Posted on 2015-02-04
4
Medium Priority
?
75 Views
Last Modified: 2015-02-08
Hi,

I got a very specific and interesting task, but i'm not sure where to begin, but very excited to get started :)
I have been working on an online Cylinder Configurator for the company I work in and everything has been working fine so far, but the next part is a bit tricky and i'm not sure where to start.

Please see attached PDF sketch.

- I need to place 4 input fields on top of an image-background, this is no problem.

Here is my problem:
- If "A" is changed, then "D" need to be adjusted accordingly.
- If "B" is changed, then "D" need to be adjusted accordingly.
- If "C" is changed, then "D" need to be adjusted accordingly.
- If "D" is changed, then "A" need to be adjusted accordingly.

Any idea how this is normally done? I would prefer to use some kind of "live updating" solution, without a "page load".


Regards,

Kenneth
input-fields.pdf
0
Comment
Question by:kgp43
[X]
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
  • 2
4 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 40588864
Simplistic example of how to bind the recalculation to whenever any of the inputs change.
In the example I hard coded the new value for A and D.  Obviously, you'll want to use your real formula instead.  Also, this example does not do anything to ensure that the values in the input fields are numeric, you'll probably want to add that in too.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>IIS7</title>
	<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<script>
function recalcInputs(element) {
  if ($(element).attr('name') == 'd') {
    //math to recalculate a goes here
    newAvalue = 12;
    $('input[name="a"]').val(newAvalue);
  } else {
    //math to recalculate d goes here
    newDvalue = 77;
    $('input[name="d"]').val(newDvalue);
  }
}

</script>
<body>
A: <input name="a" value="" type="text" onblur="javascript:recalcInputs(this)"><br/>
B: <input name="b" value="" type="text" onblur="javascript:recalcInputs(this)"><br/>
C: <input name="c" value="" type="text" onblur="javascript:recalcInputs(this)"><br/>
D: <input name="d" value="" type="text" onblur="javascript:recalcInputs(this)"><br/>
</body>
</html>

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40590840
This is the perfect task for AngularJS!
0
 

Author Closing Comment

by:kgp43
ID: 40596715
Going to look into that, exactly what i'm looking for it seems.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40596876
I've been using AngularJS for about a month, still just stumbling along at this point.  It mixes the declarative notation of HTML with the imperative structure of a programming language.  And while I think it's a laudable effort to turn a silk purse into a sow's ear, the next "real" solution for online web applications is probably still out in the future, and is probably not back-level compatible with JavaScript and HTML.  That aside, AngularJS is a really big step in the right direction!

Thanks for the points and best of luck with your project! ~Ray
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 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