Is there a way to create a dynamic array of strings on Javascript?
What I mean is, on a page the user can enter one number or thirty numbers, then he/she presses the OK button and the next page shows the array in the same order as it was entered, one element at a time.
Code is appreciated.
Ok, so you need some user input first? There’s a couple of methods of how to do that.
prompt()function which displays a popup asking the user for some input.<input type="text">fields.For the
promptmethod, collecting your strings is a doddle:(Yeah it’s not the prettiest loop, but it’s late and I’m tired….)
The other method requires a bit more effort.
onfocushandler to it.<input>s on the page and store them into an array.eg:
After that, regardless of your method of collecting the input, you can print the numbers back on screen in a number of ways. A simple way would be like this:
I’ve put this together so you can see it work at jsbin
Prompt method: http://jsbin.com/amefu
Inputs method: http://jsbin.com/iyoge