Does not append input strings dynamically on the web page

tdj

New Member
I am new in Javascripting language.I tried to build an application in which , there is one HTML page from which I get single input entry by using \[code\]Submit button\[/code\], and stores in the container(data structure) and \[code\]dynamically show that list\[/code\] i.e., list of strings, on the same page \[quote\] means whenever I click submit button, that entry will automatically append on the existing list on the same page.\[/quote\]HTML FILE :-\[code\]<html> <head> <script type = "text/javascript" src = "http://stackoverflow.com/questions/14417181/operation_q_2.js"></script> </head> <body> Enter String : <input type= "text" name = "name" id = "name_id"/> <button type="button" onClick = "addString(this.input)">Submit</button> </body></html> \[/code\]JAVASCRIPT CODE\[code\]var input = [];function addString(x) { var s = document.getElementById("name_id").value;//x.name.value; input.push(input); var size = input.length; //alert(size); printArray(size);}function printArray(size){ var div = document.createElement('div'); for (var i = 0 ; i < size; ++i) { div.innerHTML += input + "<br />"; } document.body.appendChild(div); //alert(size);}\[/code\]Here it stores the strings in the \[code\]input Array\[/code\], but unable to show on the web page. Need help please.Tell me one more thing there is one code on given link. It also not gives desired answer. Please help me overcome from this problem.\[code\]<html><body> <script> function addValue(a) { var element1 = document.createElement('tr'); var element2 = document.createElement('td'); var text = document.createTextNode(a); var table = document.getElementById('t'); element2.appendChild(text); element1.appendChild(element2); table.tBodies(0).appendChild(element1); } </script> Name: <input type="text" name="a"> <input type="button" value="http://stackoverflow.com/questions/14417181/Add" onClick='javascript:addValue(a.value)'> <table id="t" border="1"> <tr><th>Employee Name</th></tr> </table></body></html>\[/code\]
 
Back
Top