Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push user input to array

Tags:

javascript

Hi so yes this is a previous issue i have had, i have hit the books and whent back to basics adjusted a few things but im still having trouble getting the input value to push to the array can some one please help me get my head around this thanks

<!DOCTYPE html>
<html>

 <body>
  <script type="text/javascript">
   var number=["1"]
   function myFunction()
   {
    var x=document.getElementById("box");
     number.push=document.getElementById("input").value;
    x.innerHTML=number.join('<br/>'); 
   }
  </script>
 <form>
  <input id="input" type=text>
   <input type=button onclick="myFunction()" value="Add Number"/>
  </form>

 <div id="box"; style="border:1px solid black;width:150px;height:150px;overflow:auto"> 
  </div>
</body>
</html>
like image 971
Linda wolfenden Avatar asked Mar 07 '26 11:03

Linda wolfenden


1 Answers

Here is the mistake:

number.push(document.getElementById("input").value);

push is a method, not an attribute ;-)

JSFiddle

PS: Why the ; after id="box"; ? You should fix that too..! ;-)

like image 151
mbinette Avatar answered Mar 09 '26 23:03

mbinette