Search
 
SCRIPT & CODE EXAMPLE
 

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: when programmers net goes down 
Javascript :: how to check provided value is in array in javascript 
Javascript :: addAndRemoveClassJquery 
Javascript :: sort object with certain value at start of array js 
Javascript :: js rename onclick function 
Javascript :: how to calculate time taken for ajax call in javascript 
Javascript :: round value down html 
Javascript :: mongoose limit skip 
Javascript :: js lambda 
Javascript :: how to add image url in tailwindconfig .js 
Javascript :: how to do when enter is pressed javascript do smething 
Javascript :: check if computer online js 
Javascript :: generate svg from javascript 
Javascript :: disable google analytics gatsby config.js 
Javascript :: change base js 
Javascript :: color picker in react js 
Javascript :: react snack bar 
Javascript :: 15) Which of the following directive is used to initialize an angular app? A. ng-app ANSWER B.ng-model C.ng-controller D.None of the above 
Javascript :: Expo camera rotation 
Javascript :: setTilme out js 
Javascript :: JavaScript alert massage prompt 
Javascript :: nodejs check if file is running on server or client 
Javascript :: javascript sig figs 
Javascript :: juqey off click 
Javascript :: delay sleep 
Javascript :: send as form data with boundry axios 
Javascript :: str_limit function filter vuejs 
Javascript :: loop in javascript 
Javascript :: chai async test 
Javascript :: vue js debounce input 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =