#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Push from user input to array


    I need to push user input from input form to array but im doin something wrong can some one please help me to understand better thanks

    <!DOCTYPE html>
    <html>

    <body>
    <script type="text/javascript">
    var number=["1"]
    function myFunction()
    {
    var x=document.getElementById("box");
    number.push=document.getElementById("number").value;
    x.innerHTML="input";
    }
    </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>
    Javascript Code:
    [Javascript]
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    If you really want to learn more; Google "JavaScript Push() Method"... just saying.

    Code:
    <!DOCTYPE html>
    <html>
    
    <body>
    <script type="text/javascript">
    var number = ["1"];
    function myFunction()
    {
    var x = document.getElementById("input").value;
     if (x.length >= 1) {
      number.push(x);
      document.getElementById("box").innerHTML = number[number.length-1];
     }
    }
    </script>
    <form onsubmit="return false">
    <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>

IMN logo majestic logo threadwatch logo seochat tools logo