arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ibys
    New Member
    • Nov 2009
    • 8

    arrays

    hi,

    I am trying to create an array, that will prompt the user for the amount of items they have for sale, then to name the items they have for sale. I then want the correct amount of boxes to appear on screen, with labels beside each box that match the users input. I then have to do some further things, but im doing the code in sections, and before I go on to make it do the next thing, I want to make sure this part works! so far i have figured out how to write all the code for the prompts to come up and so on, and before I attempted to include the correct name beside each box, as entered by the user, it was showing me the right number of boxes on screen, for the number that was entered. but now it just comes up with the submit button :S could anyone please help, what have i done wrong?

    Code:
    <html>
    <head>
    <title>Activity 2.33</title>
    </head>
    <script type="text/javascript">
    
      var Items;
      var ItemNames=new Array();
      ItemNames[0]="value 1";
      ItemNames[1]="value 2";
      Items=prompt("How many items would you like to sell?")
      LoopCounter= 1;
      element=document.getElementsByTagName('input');
      document.write ("<form name='myform'><br><table>");
    
    for (NameCount=0; NameCount<Items; NameCount ++)
      {
        ItemNames[NameCount]= prompt("What are the names of your items","");
      }  
      while (LoopCounter<= Items)
        {
        document.write ("<tr><td>Enter the price of the " + ItemNames[count] + "</td><td><input type='text'name='"+ ItemNames[count] + "'></td></tr>");
        LoopCounter= LoopCounter+ 1;
        }
    
    document.write ("</table></form>");
    </script>
    <body>
    <tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform()
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by Ibys
    but now it just comes up with the submit button :S could anyone please help, what have i done wrong?
    you didn’t define the output in the HTML body (and you should write the <form> tags in the HTML from the start, because you need it anyway)

    Comment

    • Ibys
      New Member
      • Nov 2009
      • 8

      #3
      should the <form> tags be before or after the javascript part, or around it? I think my textbook is a bit outdated, and my teacher has just told me to do what the textbook says... not much of a help, it doesnt even mention the <form> tags! :( i have edited the HTML body to include the output, but so far I havnt been able to get it to put in the right amount for the users input, its putting its own amount there with the wrong labels! will have to have another look when i get home from work, bit stuck for now and need to get ready to go. will let you know how I go with it tonight, thanks for the help :)

      Comment

      Working...