Hi. Can I shorten this syntax it doesn't look elegant, I tried to do that but always I got more and more code. Please help. x.text3.value = x.text1.value - x.text2.value; <form name="Form1"> Variable 1: <input type="text" name="text1" value="variable1"> Variable 2: <input type="text" name="text2" value="variable2"> Equal: <input type="text" name="text3" value="equal"> </form>
<head> <script> function somethingChanged() { val1 = document.getElementById("val1"); val2 = document.getElementById("val2"); val3 = document.getElementById("val3"); val3.value = val1.value + val2.value; } </script> </head> <form name="Form1" > Variable 1: <input type="text" name="text1" value="variable1" id="val1" onchange="somethingChanged()" > Variable 2: <input type="text" name="text2" value="variable2" id="val2" onchange="somethingChanged()" > Equal: <input type="text" name="text3" value="equal" id="val3" onchange="somethingChanged()" > </form>