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.
<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.
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>
Perhaps, but it's still not working for me, nothing happens when I click the Add button. Maybe it's just my web browser.
Works in IE as well, but I had to accept the script warning. By default, IE disallowed the Javascript for me...