[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Order form blues

Posted on 2012-08-19
3
Medium Priority
?
204 Views
Last Modified: 2012-12-07
Hi Experts,
I am trying to collect information from an order form but only wish to use the information from the form where the quantity ordered is greater than 0 and perform calculations based on that.
I had thought of trying to create an array of each item and selecting only the ones with the qty greater than 0 or creating an object with the needed properties to hold the information from each form.
The page is visible here and if you're firebugging the Javascript is there too. The form in question is the one with the fruit juices.
If there's an easier way than the ones I outlined please let me know.
Merçi
Coke
0
Comment
Question by:cokefour
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Barry62
ID: 38309805
Building an array would work fine.

juiceOrderArray = new Array("qtyjuice1", "qtyjuice2","qtyjuice3","qtyjuice4","qtyjuice5","qtyjuice6","qtyjuice7","qtyjuice8","qtyjuice9","qtyjuice10");
for(i=0; i<juiceOrderArray.length; i++) {
        if(juiceOrderArray[i] > 0){
	      "Add to calculation routine".
        }
}

Open in new window

0
 
LVL 5

Author Comment

by:cokefour
ID: 38311245
DO you know how I would be able to associate each price and name with its quantity?
0
 
LVL 8

Accepted Solution

by:
Barry62 earned 1500 total points
ID: 38311544
OK, first of all, if you want to keep the associations between the name, price and quantitiy, you'll have to modify the juicid for each item to be the same format as the price and quantity names.  In other words, the name for Very Peachy would be juiceid1, like the quantity name is qtyjuice1, etc.  Once you do that, you can use a multidimensional array:

juiceOrderArray = new Array(10); 
for(var i=0;i<10;i++){
  juiceOrderArray[i]=[' ',' ',' ']; 
}
juiceOrderArray[0][0]=document.juiceid1.value;
juiceOrderArray[0][1]=document.juiceprice1.value;
juiceOrderArray[0][2]=document.qtyjuice1.value;
juiceOrderArray[1][0]=document.juiceid2.value;
juiceOrderArray[1][1]=document.juiceprice2.value;
juiceOrderArray[1][2]=document.qtyjuice2.value;
juiceOrderArray[2][0]=document.juiceid3.value;
juiceOrderArray[2][1]=document.juiceprice3.value;
juiceOrderArray[2][2]=document.qtyjuice3.value;
juiceOrderArray[3][0]=document.juiceid4.value;
juiceOrderArray[3][1]=document.juiceprice4.value;
juiceOrderArray[3][2]=document.qtyjuice4.value;
juiceOrderArray[4][0]=document.juiceid5.value;
juiceOrderArray[4][1]=document.juiceprice5.value;
juiceOrderArray[4][2]=document.qtyjuice5.value;
juiceOrderArray[5][0]=document.juiceid6.value;
juiceOrderArray[5][1]=document.juiceprice6.value;
juiceOrderArray[5][2]=document.qtyjuice6.value;
juiceOrderArray[6][0]=document.juiceid7.value;
juiceOrderArray[6][1]=document.juiceprice7.value;
juiceOrderArray[6][2]=document.qtyjuice7.value;
juiceOrderArray[7][0]=document.juiceid8.value;
juiceOrderArray[7][1]=document.juiceprice8.value;
juiceOrderArray[7][2]=document.qtyjuice8.value;
juiceOrderArray[8][0]=document.juiceid9.value;
juiceOrderArray[8][1]=document.juiceprice9.value;
juiceOrderArray[8][2]=document.qtyjuice9.value;
juiceOrderArray[9][0]=document.juiceid10.value;
juiceOrderArray[9][1]=document.juiceprice10.value;
juiceOrderArray[9][2]=document.qtyjuice10.value;

Open in new window


Then do the loop to check for > 0:

for(x=0; x<10; x++) {
        if(juiceOrderArray[x][2] > 0){
	      "Add to calculation routine".
        }
}
                                            

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question