I have 2 text boxes A and B I want the answer A-B displayed on A Text box 'onchange' event of B
Please help me
Thanks
God Bless

Eranga

hi,
first, please try with some code then post your code here for help.
Anyway try with example script:

function test()
{
var x=document.getElementById("A");
document.getElementById("A")=x-document.getElementById("B");
}

Use this test() on'onchange' for A text box.

Please post your required peice of code..
All the best.

Member Avatar for diafol

Why is this php?

I think this code will help you .:-)

<HTML>
  <HEAD>
  <TITLE>Test Input</TITLE>
  <SCRIPT LANGUAGE="JavaScript">
  
  function validate (form) {
   var First = form.inputbox.value;
   var Sec = form.inputbox2.value;
   alert( " Result = " +First+ "-" +Sec);
   document.getElementById("nm").value=First+ "-" +Sec;
  }
  </SCRIPT>
  </HEAD>
  <BODY>
  <FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
 First Name <INPUT id ="nm" TYPE="text" NAME="inputbox" VALUE="" ><P>
 Second Name  <INPUT TYPE="text" NAME="inputbox2" VALUE="" OnChange="validate(this.form)" ><P>
  
  </FORM>
  </BODY>
  </HTML>

It is Javascript problem. Move to Javascript forum.

Moving to Javascript.

document.getElementById("nm").value=First+ "-" +Sec line do no give the answer
it just shows the equation
ex: 500-400 answer should be 100 but it show as 500-400

Please help
thanks
God Bless

Eranga

How do a equation on a formatted text box
EX: TextBox A = formatted(14,500.00) Text box B - formatted(1,1200.00)
TextBox A = 14,500.00 - 1,1200.00 answer comes as 'Nan'

Please help
Thanks
God Bless

Eranga

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.