Solved

Automatically adjust numbers in input fields to match max value

Posted on 2015-02-04
4
73 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 110

Accepted Solution

by:
Ray Paseur earned 500 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 110

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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