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,636
  • 22
  • 26
  • 40
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
  • 316
  • 5
  • 14
0

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

document.getElementById("nameId").innerHTML=yourdata...
Ferdinando
  • 958
  • 1
  • 11
  • 23