Reading an input from a textbox and storing it in an array in JavaScript - Stack Overflow

I have a <textarea> that allows text to be inputted in the form of a string. Then the users click

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); and array.pop(); or array[i] – Ian Commented Dec 18, 2012 at 17:39
Add a ment  | 

1 Answer 1

Reset to default 2

You 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信