-2

In this program, i want to show the answer in the other textbook once the textbook contains a value is clicked. Also I want to do this without using a calculate button.

So i tried to implement this but failed.

 function mm() {



   if (isNaN(document.getElementById("m"))) {
     console.log("Null");


   } else {
     console.log("OK");

     var x = document.getElementById("m").value;
     var y = x * 1000;

     document.getElementById("mm")[0].innerHTML = y;


   }

 }

 function m() {


   if (isNaN(document.getElementById("mm"))) {
     console.log("Null");

   } else {

     console.log("OK");
     var x = parseInt(document.getElementById("mm").value);
     var y = x / 1000;
     document.getElementById("m")[2].innerHTML = y;

   }


 }
<div>
  <table>
    <tr>
      <td>mm</td>
      <td>
        <Input type='text' name='mm' onclick="mm();" />
      </td>
    </tr>

    <tr>
      <td>m</td>
      <td>
        <Input type='text' name='m' onclick="m();" />
      </td>
    </tr>

  </table>
</div>
rama41222
  • 65
  • 1
  • 7

1 Answers1

2

So finally I was able to get my code working using the on input event.

function mm(p) {





  console.log("OK");

  var x = p;
  var y = x * 1000;

  document.getElementById("mm").value = y;



}

function m(p) {


  console.log("OK");
  var x = p;
  var y = x / 1000;
  document.getElementById("m").value = y;

}
<table>
  <tr>
    <td>m</td>
    <td>
      <Input type='text' id='m' oninput="mm(this.value);" />
    </td>
  </tr>

  <tr>
    <td>mm</td>
    <td>
      <Input type='text' id='mm' oninput="m(this.value);" />
    </td>
  </tr>

</table>
rama41222
  • 65
  • 1
  • 7