Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    85
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array How to Question

    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!!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •