[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Automatically adjust numbers in input fields to match max value

Posted on 2015-02-04
4
Medium Priority
?
76 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

656 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