im dumb im dumb - 1 month ago 11
HTML Question

javascript getting my textbox to display a variable

So I have some basic code in html here, i just have two textbox which u can type numbers in and when you click the button, it adds em both up, and in a perfect world, it would display the answer in that third textbox.

<html>
<head>
</head>
<script type="text/javascript">
function myfunction()
{
var first = document.getElementById("textbox1").value;
var second = document.getElementById("textbox2").value;
var answer = +first + +second;
var textbox3 = answer;
}
</script>
<body>
<input type="text" name="textbox1" id="textbox1" />
+
<input type="text" name="textbox2" id="textbox2" />
<input type="submit" name="button" id="button1" onclick="myfunction()" value="=" />

<input type="text" name="textbox3" id="textbox3" readonly="true"/>
<br />
Your answer is: --
</body>
</html>


however, i can't the the answer to display in that textbox3. Does anyone know how to assign a value to that third textbox from a variable?

also, as an added bonus, if anyone knows a way to also make the last line "Your answer is: --" display the answer as well, that would be amazing.

Answer
<html> 
<head> </head> 
<script type="text/javascript">
function myfunction() { 
var first = document.getElementById("textbox1").value;
 var second = document.getElementById("textbox2").value; 
var answer =parseFloat(first)+parseFloat(second);

var textbox3 = document.getElementById('textbox3');
textbox3.value=answer;
 } 
</script>
 <body> 
<input type="text" name="textbox1" id="textbox1" /> + <input type="text" name="textbox2" id="textbox2" /> 
<input type="submit" name="button" id="button1" onclick="myfunction()" value="=" />
<br/>
Your answer is:--
<input type="text" name="textbox3" id="textbox3" readonly="true"/>
</body>
 </html>