Solved

Automatically adjust numbers in input fields to match max value

Posted on 2015-02-04
4
65 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
  • 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 108

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 108

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now