SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Calculating price
-
Jul 30, 2003, 02:13 #1
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Calculating price
Hi there,
I need to calculate a price based on selections made by the client. The following works fine, but I would need to add some extra options which I will explain below the code.
Code:function calculatePrice() { ammount = 0; //Calculating prices if (document.reg.fee[0].checked) { ammount = parseInt(ammount + 995); } if (document.reg.fee[1].checked) { ammount = parseInt(ammount + 1395); } if (document.reg.fee[2].checked) { ammount = parseInt(ammount + 645); } if (document.reg.fee_accomp_person.checked) { ammount = parseInt(ammount + 100); } // Total that will be displayed document.reg.fee_total.value = parseInt(ammount); }
Is there a why with Javascript to check only the first three letters to find out which price is applicable? (Wildcard)
How whould I address a drop down box? something like document.reg.dropdown.value ?
Thanks for any help,
regards ASchweti
-
Jul 30, 2003, 04:25 #2
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
quick answer: not really.
what are you trying to do have the 'reg' and 'dis' separate out? before, during, or after the selection? If before, simply sort the array before creating the selection list. if during, the hitting 'r' should bring up the first 'reg'. if after, why?
more info is needed.
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Jul 30, 2003, 04:50 #3
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
I am using the onClick event, for a dropdown most likely onChange.
So if I check the box named fee_accomp_person (please see code above) 100 gets added to the ammount.
If the value of the dropdown start with "reg" I would like to add e.g. 200 to the ammount if it start with dis only 150.
Is that what your were asking for?
Regards ASchweti
-
Jul 30, 2003, 07:41 #4
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am thinking of something like...
Code:if (document.reg.dropdown.value == 'reg%') {ammount1 = parseInt(ammount1 + 150);}
Regards ASchweti
PS: This code might be totally dumb, but I am NOT a Javascript programmer
-
Jul 30, 2003, 08:38 #5
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
var f = document.reg;
var value = f.dropdown.options[f.dropdown.selectedIndex].value;
var valueType = value.subtstring( 0, 3 );
valueType now holds "REG" or "DIR" dependant upon what is selected. This may not be the best way to integrate it into your script, but I think you get the idea.
-
Jul 30, 2003, 08:50 #6
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi beetle,
I think I get the idea, but I get "Object doesn't support this method". Only thing I changed compared to your code is the "dropdwon", since the name of the dropdown box is actually "client".
Any idea?
Regards ASchweti
-
Jul 30, 2003, 09:10 #7
-
Jul 30, 2003, 09:20 #8
- Join Date
- Jun 2003
- Location
- Germany
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh Jesus, could have seen that as well. I even read about substring in my smart O'Reilly book, but didn't see the typo
Well, works fine...
Thanks for your support,
ASchweti
Bookmarks