Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to display words from an array in a box in javascript

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Demo of adding element to an array</title>
</head>

<body>
 <script type="text/javascript">
var data = new Array(); // creating array

function add_element(){
data.push(document.getElementById('t1').value); // adding element to array
document.getElementById('t1').value=''; // Making the text box blank
disp(); // displaying the array elements
}

function disp(){
var str='';
str = 'total number of elements in data array : ' + data.length + '<br>';
for (i=0;i<data.length;i++) 
{ 
str += i + ':'+data[i] + "<br >";  // adding each element with key number to variable
} 

document.getElementById('disp').innerHTML=str; // Display the elements of the array
}
</script>

<input type=text  id='t1'><input type=button value='Add' onClick='add_element()';>
<div id=disp></div>

</body>
</html>
Source by www.plus2net.com #
 
PREVIOUS NEXT
Tagged: #display #words #array #box #javascript
ADD COMMENT
Topic
Name
3+2 =