Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading input from user and displaying it back on the page

Status
Not open for further replies.

n8rt8r69

Technical User
Dec 8, 2009
3
US
I am having trouble doing a simple part of a web page where all I need to do is read in two integers (given by the user), display them back onto the webpage (in the form of a label) along with an answer to a simple calculation such as adding them....some of the code that I have so far is posted below:
Code:
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<script type="text/javascript" language="javascript">
	function mathall()
	{
		var firstnumber = parseInt(frmOne.Number1.value);
		var secondnumber = parseInt(frmOne.Number2.value);
		frmOne.Answer.value = (firstnumber + secondnumber);	
	}		
</script>
</head>

<body>
<form method="post" name="frmOne">
	<input id="Number1" type="text" /><br/>
	+<br/>
	<input id="Number2" type="text"/><br/>
	<label id="Answer" name="Answer"></label><br/>
	<input name="Equals" type="button" value="Answer" onclick="mathall()"/><br/>	
</form>
</body>
 
Try using document.getElementById(id).value rather than frmOne.xxxxx.value.

Lee
 
I did that before, and I just tried it again, but I keep getting an error saying that an object is expected down by
Code:
<input name="Equals" type="button" value="Answer" onclick="mathall()"/><br/>

I'm wondering if I just don't know how to format the result/answer correctly in the script
 
Try this:

Code:
var firstnumber = parseInt(document.forms.frmOne.Number1.value);
        var secondnumber = parseInt(document.forms.frmOne.Number2.value);
        document.getElementById('Answer').innerHTML = (firstnumber + secondnumber);

Oh and Labels don't have a Value property. They have an innerHTML property instead.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Ahhhhh Thank You!!! it was that innerHTML property that was kickin my derriere
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top