|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need a little help with this
Hi;
l am a little stuck on gathering all the results and adding them together. I have tried different ways to get them but had no luck. Each of these variable has the total of each drop down menu. Now I trying to gather each drop down menu then add them to get a the total of everhing. the variable that hole the total of each drop down menu. stotal dtotal ctotal ptotal Code: <script type="text/javascript"> function ServiceItemSelected(){ var stotalselected; var select; var sitem ; var stotal; select = document.forms['FrontPage_Form1'].elements['Service']; sitem = select.options[select.selectedIndex].text switch (sitem){ case "Choose one": alert("You have made a wrong selection") break; case "Internet Digi": stotal= 4 * 0.4; //alert(stotal.toFixed(2)) break; case "Internet Vid": stotal= 3 * 0.4; //alert(stotal.toFixed(2)) break; case "Internet Only": stotal= 2 * 0.4; //alert(stotal) break; case "Digital": stotal= 2 * 0.4; //alert(stotal) break; case "B2": stotal= 1 * 0.4; //alert(stotal) break; case "B1": stotal= 0 * 0.4; //alert(total) break; default: stotal= 0 * 0.4; //alert(total) break; } } function DurationItemSelected(){ var dselect; var ditem; var dtotal; dselect = document.getElementById("Duration") ditem = dselect.options[dselect.selectedIndex].text switch (ditem){ case "Choose one": alert("You have made a wrong selection") break; case "Three or more years": dtotal= 4 * 0.2; //alert(dtotal.toFixed(2)) break; case "One to two years": dtotal= 2 * 0.2; //alert(dtotal.toFixed(2)) break; case "Less than a year": dtotal= 1 * 0.2; //alert(dtotal.toFixed(2)) break; default: dtotal= 0 * 0.2; //alert(dtotal.toFixed(2)) break; return dtotal; } } function DelinquentItemSelected(){ var cselect; var citem; var ctotal; cselect = document.getElementById("Delinquent") citem = cselect.options[cselect.selectedIndex].text switch (citem){ case "Choose one": alert("You have made a wrong selection") break; case "0": ctotal= 4 * 0.3; //alert(ctotal.toFixed(2)) break; case "1 - 3": ctotal= 2 * 0.3; //alert(ctotal.toFixed(2)) break; case "4 - 6": ctotal= 0 * 0.3; //alert(ctotal.toFixed(2)) break; default: ctotal= 0 * 0.3; //alert(ctotal.toFixed(2)) break; return ctotal; } } function PromosItemSelected(){ var pselect; var pitem; var ptotal; pselect = document.getElementById("Promos") pitem = pselect.options[pselect.selectedIndex].text switch (pitem){ case "Choose one": alert("You have made a wrong selection") break; case "No Promo": ptotal= 4 * 0.1; //alert(ptotal.toFixed(2)) break; case "Promo within one year": ptotal= 2 * 0.1; //alert(ptotal.toFixed(2)) break; case "Promo within 6 months": ptotal= 1 * 0.1; //alert(ptotal.toFixed(2)) break; default: ptotal= 0 * 0.1; //alert(ctotal.toFixed(2)) break; return ptotal; } } This where I am having the problem. I don't how to pass the results of each drop down to get the total. I know it's wrong! However how can I fix it? function SumSelected(stotal, dtotal, ctotal, ptotal){ var TotalSumSelected = stotal + dtotal + ctotal + ptotal; alert(TotalSumSelected.toFixed(2)) } </script></p> |
|
#2
|
||||
|
||||
|
you have to call it like this:
SumSelected(ServiceItemSelected(), DurationItemSelected(), DelinquentItemSelected(), PromosItemSelected()); |
|
#3
|
|||
|
|||
|
Thank you for taking the time to help. I am a little unclear on something correct me if I am wrong SumSelected is a variable right? I did the the following changes and I got this error.
function grandtotal(){ SumSelected(ServiceItemSelected(), DurationItemSelected(), DelinquentItemSelected(), PromosItemSelected()); Line: 612 var SumSelected = stotal + dtotal + ctotal + ptotal; alert(SumSelected.toFixed(2)) } The error I got is this Line: 612 Char: 1 error: Object expected |
|
#4
|
||||
|
||||
|
no, SumSelected is a function.
you need only to call it and the function contains code that doing the job you want. you can't refer to stotal, dtotal, ctotal and ptotal as those are variables inside different functions. |
|
#5
|
|||
|
|||
|
You have to excuse me I am new to javascript! Here what I did and I got a diferent error
function SumSelected(ServiceItemSelected(), DurationItemSelected(), DelinquentItemSelected(), PromosItemSelected()) { line: 610 char: 41 error: '}' var total= ServiceItemSelected + DurationItemSelected + DelinquentItemSelected + PromosItemSelected; alert(total.toFixed(2)) } |
|
#6
|
||||
|
||||
|
no.
have such code in your page: Code:
<script language="javascript"> SumSelected(ServiceItemSelected(), DurationItemSelected(), DelinquentItemSelected(), PromosItemSelected()); </script> and have the function as you posted it here. that's all... |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Need a little help with this |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|