Michael
Michael

Reputation: 235

Show content of two textboxes in a third textbox in real time

I have 2 textboxes: Box1 and Box2.

Using JavaScript I would like a third box to show: "ContentOfBox1 metre x ContentOfBox2 metre" in real time.

Upvotes: 0

Views: 2513

Answers (2)

Ash Burlaczenko
Ash Burlaczenko

Reputation: 25465

Place an onchange event on both your text boxes like so

<input id="text1" onchange="modifyText3" />
<input id="text2" onchange="modifyText3" />
<input id="text3" />

Then your javascript would be

function modifyText3()
{
    var val1 = document.getElementById("text1").value;
    var val2 = document.getElementById("text2").value;
    document.getElementById("text3").value = val1 + " meter x " + val2 + " meter";
}

Hope this helps.

Upvotes: 2

koder
koder

Reputation: 554

Create 3 text boxes and add js function "changeOutput" on onChange event of 2 input boxes.

<input id="input1" onchange="changeOutput()" value="" />
<input id="input2" onchange="changeOutput()" value="" />
<input id="output" value=""/>

And the javascript function is

function changeOutput(){
    var input1 = document.getElementById("input1").value;
    var input2 = document.getElementById("input2").value;
    document.getElementById("output").value = val1 + " metre x " + val2 + " metre";
}

Upvotes: 0

Related Questions