3

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.

1
  • 4
    var value = document.getElementById("id").value; var array = []; array.push(value); and array.pop(); or array[i] Commented Dec 18, 2012 at 17:39

1 Answer 1

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]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.