Click to See Complete Forum and Search --> : need array script
1christine
12-07-2003, 03:03 PM
I need a script that prompts visitors to web page to answer 5 individual questions. Each answer needs to be assigned to an array and then use a for loop to print the info to the screen.
Would greatly appreciate assistance.
jontheman12
12-07-2003, 04:33 PM
um... :(
check out these free script sources:
http://www.freescripts.com
http://www.javascriptcity.com
http://www.free-javascripts.com/
http://www.javascriptsearch.com/
:D :)
fredmv
12-07-2003, 04:46 PM
If you aren't going to provide information in which pertains to the original question, simply don't post. Anyone can find resources — this is a specific question that requires specific information.
Are you looking for something like this?<script type="text/javascript">
var foo = [], i = 0;
for(i=0; i<5; i++) foo[i] = prompt('Enter data for element ' + i + ':', '');
for(i=0; i<foo.length; i++) document.writeln('foo[' + i + '] = ' + foo[i] + '<br />');
</script>
1christine
12-07-2003, 08:02 PM
That is very close to what I'm looking for.
However, I need to ask 5 separate questions.
I think I need to create 5 separate prompts but how do I apply the responses to the array?
Also, how do I call the function to print the information?
Thanks for any help.
woodknut
12-08-2003, 10:54 AM
You could pre-load a message array with the unique prompts then use the code suggested above and replace :
prompt('Enter data for element ' + i + ':', '')
with
prompt(msg[i] + ':', '') to display the unique message.
msg[0] = 'Whats your name'
msg[1] = 'Who's your daddy'
msg[2] = 'Is he rich like me'
etc.
I'm not that proficient with this coding but think it'll work.
Dan.
edit for spelling.