1. If you had an old account at the OLD OLD Nexopia, you can get that account back by resetting your password.

    Click Here to Reset Your Old Account's Password.

    Alternatively, you can Register a New Account!

Is anyone on here familiar with JavaScript?

Discussion in 'Computers' started by FaelanTheFox, Aug 7, 2016.

  1. FaelanTheFox

    FaelanTheFox Newbie

    Blogs:
    1
    Joined:
    Aug 3, 2016
    Posts:
    44
    Likes Received:
    26
    And if so, could you help me identify what I'm doing wrong with some code? I don't see why it shouldn't be working. Also don't worry it's very easy stuff. I'm trying to teach myself how to get data from an HTML form and write it to the page using a javascript function.
     
  2. SailorMan

    SailorMan Member

    Blogs:
    1
    Joined:
    Aug 13, 2008
    Posts:
    131
    Likes Received:
    70
    I know enough about it that i hate it and dont touch it.
     
  3. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    sure. ask away.
     
  4. FaelanTheFox

    FaelanTheFox Newbie

    Blogs:
    1
    Joined:
    Aug 3, 2016
    Posts:
    44
    Likes Received:
    26
    <html>
    <body>

    <form id="theform">
    Enter Value:
    <input type="text" name="value" size="15" maxlength="30"/>
    <button onclick="outputname()">Submit</button>

    </form>


    <script>

    function outputname()
    {
    var x,y;
    x=document.getElementById("theform");
    y=x.elements["value"].value;
    document.getElementById("practice").innerHTML=y;
    }

    </script>


    <p id="practice"></p>
    </body>
    </html>

    This little bit of code here is pretty straight forward, but when I click the button, the value pops up below it like it should, but only for a split second, and then disappears. I want the value to stay there, and then every additional value that gets entered to be placed below the last.
     
  5. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    Code:
    
    <html>
    <head>
    	<title>JavaScript Demo</title>
    	<script>
    		function addToList()
    		{
    			var elmtVal = document.getElementById("field").value;
    			var curElmt = document.getElementById("outputZone");
    
    			if (elmtVal != "")
    			{
    				var par = document.createElement("P");
    				var span = document.createElement("SPAN");
    				span.innerText = elmtVal;
    				par.appendChild(span);
    				curElmt.appendChild(par);
    			}
    		}
    		function clearList()
    		{
    			document.getElementById("outputZone").innerHTML="";
    		}
    	</script>
    </head>
    <body>
    
    	Enter Value:
    	<input id="field" type="text" name="value" size="15" maxlength="30" />
    	<button onclick="addToList()">Add</button>
    	<button onclick="clearList()">Clear</button>
    
    
    	<div id="outputZone">
    
    	</div>
    </body>
    </html>
    
    
     
    • Like Like x 1
    Last edited: Aug 8, 2016
  6. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    I believe that's roughly what you wanted?
     
  7. FaelanTheFox

    FaelanTheFox Newbie

    Blogs:
    1
    Joined:
    Aug 3, 2016
    Posts:
    44
    Likes Received:
    26
    Perhaps, but it's still not working for me, nothing happens when I click the Add button. Maybe it's just my web browser.
     
  8. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    The code runs in Chrome. That was my test browser.
     
  9. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    Works in IE as well, but I had to accept the script warning. By default, IE disallowed the Javascript for me...
     
  10. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    @FaelanTheFox
    did you get your JS working?
    also, i coded it to "not add blanks"..
     
  11. FaelanTheFox

    FaelanTheFox Newbie

    Blogs:
    1
    Joined:
    Aug 3, 2016
    Posts:
    44
    Likes Received:
    26
    I haven't messed with it anymore quite yet, getting stuff ready for school to start in a few weeks.
     
  12. djfly

    djfly Smiter of Spam

    Blogs:
    3
    Joined:
    Jan 20, 2004
    Posts:
    2,051
    Likes Received:
    847
    alrighty - lmk if you don't get it figured.
     
  13. Cijo Cyril

    Cijo Cyril Guest

    Blogs:
    0

Share This Page