Hi, I have 5 Numeric fields in my from, I am using onkeyup to check for numeric values only, now I have a total field also. I would like to have a sum of the values entered in the 5 fields to be shown automatically on this total field. How to do this, please help.

Recommended Answers

All 2 Replies

You need to get the display element by either go through DOM (parentElement.subelementName...) or directly access via the element ID (document.getElementById(elementId)). Then assign/append the value to the display element's value or innerHTML depending on what type of your display element (input/textarea -> value, div/span -> innerHTML). If you still does not know how to do it, please post your code portion.

Below is the code i used to apply conditional formatting to a table i was pulling from a mySQL database. If the value in the cell was bigger or smaller than 200 i would flag it a different background colour. I think you might be able to adapt this for your application!

<script type="text/javascript">
$(document).ready(function() {
var refreshId = setInterval(function() {

         $("#recent tr:not(:first)").each(function() { 
             
             var tempresult = $(this).find("td:nth-child(3)").text();
             var setpoint = 200;
             
             if (tempresult < setpoint){
                 $(this).find("td:nth-child(3)").css("background-color", "#00FF00");
             }
             else if(tempresult > setpoint){
                 $(this).find("td:nth-child(3)").css("background-color", "#FF0000");
				 $(this).find("td:nth-child(3)").css("color", "white");
             }
         });

},1000);
});
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.