I have a <textarea>
that allows text to be inputted in the form of a string. Then the users clicks on a button which displays what they have inputted back to them in a text area within a table.
I need to use an array to store what has been inputted by the user, and then display it back out into another <textarea>
element within a table from the array, where the user input is stored from the input box.
Any pointers on how to fill up an array and stacks, from a user input would be great.
I have a <textarea>
that allows text to be inputted in the form of a string. Then the users clicks on a button which displays what they have inputted back to them in a text area within a table.
I need to use an array to store what has been inputted by the user, and then display it back out into another <textarea>
element within a table from the array, where the user input is stored from the input box.
Any pointers on how to fill up an array and stacks, from a user input would be great.
Share edited Jul 28, 2016 at 2:39 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Dec 18, 2012 at 17:38 beccas_100beccas_100 411 gold badge1 silver badge5 bronze badges 1-
4
var value = document.getElementById("id").value; var array = []; array.push(value);
andarray.pop(); or array[i]
– Ian Commented Dec 18, 2012 at 17:39
1 Answer
Reset to default 2You can declare your array like this
var yourArray = new Array();
or
var yourArray = [];
To add items to array:
yourArray.push(yourString);
To get you can use indexing like (almost any other language)
yourArray[i]
You can even set as an object array like this:
yourArray.push({ text : 'blablabla'})
So, in your case, filling up the array could be something like this:
var inputText = document.getElementById('id_of_input').value;
yourArray.push(inputText);
// show it
for(var i=0; i<yourArray.length; i++) {
alert(yourArray[i]);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744808170a4594904.html
评论列表(0条)