0

I want to create a function to change the value of targeting textbox but I can't figure out what's wrong with my code.

<form name="formcalc">
  <input type="text" value="1" name="A" >
  <input type="button" value="Change" onClick="change(A)">
  <br>
  <input type="text" value="2" name="B" >
  <input type="button" value="Change" onClick="change(B)">
</form>
<script>
function change(x) {
       document.formcalc.x.value = 3;
}
</script>
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
13eforeu
  • 3
  • 1
  • https://stackoverflow.com/questions/4173391/getting-dom-element-value-using-pure-javascript – Quer Oct 20 '18 at 11:06

2 Answers2

0

As you are sending the element directly to the function, below will work

function change(x) {
   x.value = 3;
}
Jitan Gupta
  • 454
  • 6
  • 18
0

Try to Add id attribute in input type=text and call them with

document.getElementById("nameId").innerHTML=yourdata...
Ferdinando
  • 964
  • 1
  • 12
  • 23