473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

arrays

9
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?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Activity 2.33</title>
  4. </head>
  5. <script type="text/javascript">
  6.  
  7.   var Items;
  8.   var ItemNames=new Array();
  9.   ItemNames[0]="value 1";
  10.   ItemNames[1]="value 2";
  11.   Items=prompt("How many items would you like to sell?")
  12.   LoopCounter= 1;
  13.   element=document.getElementsByTagName('input');
  14.   document.write ("<form name='myform'><br><table>");
  15.  
  16. for (NameCount=0; NameCount<Items; NameCount ++)
  17.   {
  18.     ItemNames[NameCount]= prompt("What are the names of your items","");
  19.   }  
  20.   while (LoopCounter<= Items)
  21.     {
  22.     document.write ("<tr><td>Enter the price of the " + ItemNames[count] + "</td><td><input type='text'name='"+ ItemNames[count] + "'></td></tr>");
  23.     LoopCounter= LoopCounter+ 1;
  24.     }
  25.  
  26. document.write ("</table></form>");
  27. </script>
  28. <body>
  29. <tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform()
  30. </body>
  31. </html>
Nov 16 '09 #1
2 1417
Dormilich
8,658 Expert Mod 8TB
@Ibys
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)
Nov 16 '09 #2
Ibys
9
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 :)
Nov 17 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.