Link to home
Start Free TrialLog in
Avatar of bolenka
bolenka

asked on

What is the best way to display a calculated value in an html page?

Hi All:
I have a bunch of fields that are calculated onblur and the total is kept track of and submitted to the database using a hidden input. The calculated value currently looks like this:
<tr><td><input id=1 value=100 onBlur=runrecalculate></input></td></tr>
<tr><td><input id=2 value=200 onBlur=runrecalculate></input></td></tr>
<tr><td><input id=3 value=300 onBlur=runrecalculate></input></td></tr>
<tr><td class="classtext"><input id=inputSum  value=number type=hidden/> 600</td></tr>

The inputSum needs to change the "text" of the td with the class classtext...but, I don't know how to access the text in the cell..Is it better to change the hidden input to a textbox, or to use a label...the problem is, the value isnot changing, I think each browser is handling this differently and I don't know why...would it be better to just use a textbox or a label, if so, please send code...HELP PLEASE:)
BTW, this is not my code...it was there already and I need to make it work...

SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could also change the hidden field to readonly or disabled and show the value there.  I'll have to test that to make sure your JavaScript calculator can modify the value.

Is it the read only data or user will have an option to change the input values (100, 200, 300)?

please check the code for running total
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<script>
	function runrecalculate()
	{
		var content;
		content = Number(document.getElementById('a1').value) + Number(document.getElementById('a2').value) + Number(document.getElementById('a3').value);
		document.getElementById('inputSum').value = content;
	}
</script>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<table>
<tr><td><input id=a1 value=100 onchange=runrecalculate()></input></td></tr>
<tr><td><input id=a2 value=200 onchange=runrecalculate()></input></td></tr>
<tr><td><input id=a3 value=300 onchange=runrecalculate()></input></td></tr>
<tr><td class="classtext"><input id=inputSum  value="600" type=text readonly/></td></tr>
</table>
</BODY>
</HTML>

Open in new window

Already mentioned readonly om_prakash_p.

Yes you can change the value of readonly and disabled fields in the runrecalculate function, so you have at least three ways to choose from to show the value without the user changing it.

http://www.rodsdot.com/javascript/Show_Hidden_Value.asp
Avatar of bolenka
bolenka

ASKER

the user can change the values 100, 200 or 300 and when they tab off of them, the total automatically chages...the problem is there could be more than one calculated field on the page...so how do I even traverse the dom to change the total? thanks so much:)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial