javascript php html jquery ajax SOMETHING question. should be easy?

if i have 3 blank text fields, and i type "1" into one of them and "2" into the other one,

how do i make the 3rd one say "3" automatically WITHOUT having to click a submit button????

PHP won't do this but the base program i'm using is php and html.

thx
Philip, i appreciate the answer, but i think i failed to mention that if you enter 5 in one and 3 in the other the third should say 8.. in other words the two fields need to add
 
I built this based on your question:

<html>
<head>
<script type="text/javascript">
function checkfirstTwo()
{
var firstvalue = document.getElementById('one').value;
var secondvalue = document.getElementById('two').value;
if (firstvalue == 1 && secondvalue == 2)
{
document.getElementById('three').value = 3;
}
}
</script>
</head>
<body>

<input type='text' id="one" onkeyup="checkfirstTwo()"></input>
<input type='text' id="two" onkeyup="checkfirstTwo()"></input>
<input type='text' id="three" onkeyup="checkfirstTwo()"></input>


</body>
</html>
 
This is pure JavaScript/jQuery, whichever you are willing to use.
In HTML DOM, there is a JavaScript executable called "onChange" which, when the element changes, executes a JavaScript function/statement.
In your case, you will want something like this:
<form name='addThis'>
<input type='text' onChange='add()' id='txt1' name='txt1'/>< br />
<input type='text' onChange='add()' id='txt2' name='txt2'/>< br />
<input type='text' onFocus='this.blur()' id='txt3' name='txt3'/>
</form>

In your JavaScript code, you will use the function add() and check if both text fields have values, if not, stop. If they do, make sure they are integers. And if they are, add them and set the value of txt3 to that value added together. The "onFocus='this.blur()'" makes it so that the user can copy the content of the text field, but not able to type/edit it.
Good Luck!
If you need further assistance/advice, feel free to contact me.
 
Back
Top