...

View Full Version : Array How to Question



treepixie
03-11-2004, 07:36 PM
:confused: I need a piece of info to help me get started on my next project.... If I prompt the visitor to enter a list, such as a list of friends, how do I save those names to an array? All I can think of is something like, "var friends = prompt(please enter the names of all your friends. Enter 'End' when you are finished." When the visitor finishes entering then names by typing in "End", I want to display the names back, one by one, and ask them to enter a gift suggestion for each friend Then I want to save those gifts in a separate parallel array. If you can get me started, I'll see how far I can go before I have to ask for additional help!! Thanks!!:rolleyes:

Mr J
03-11-2004, 10:09 PM
This should get you started


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
<script>
names=new Array()
index= -1

function getme(){
document.getElementById("mynames").innerHTML=""
index++

var friends = prompt("please enter the names of all your friends. Enter 'End' when you are finished.","" )
names[index]=friends


if(names[index]=="end"){

for(i=0;i<names.length;i++){
document.getElementById("mynames").innerHTML+=names[i]+"<br>"
}

}
else{
getme()
}

}
</script>

</HEAD>
<BODY onload="getme()">
<div id="mynames"></div>
</BODY>
</HTML>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum