HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 2nd, 2004, 09:11 AM
calibus calibus is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 126 calibus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 5
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>

Reply With Quote
  #2  
Old November 2nd, 2004, 09:19 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,891 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 7 h 53 m 18 sec
Reputation Power: 1537
you have to call it like this:
SumSelected(ServiceItemSelected(), DurationItemSelected(), DelinquentItemSelected(), PromosItemSelected());

Reply With Quote
  #3  
Old November 2nd, 2004, 09:59 AM
calibus calibus is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 126 calibus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 5
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

Reply With Quote
  #4  
Old November 2nd, 2004, 10:14 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,891 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 7 h 53 m 18 sec
Reputation Power: 1537
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.

Reply With Quote
  #5  
Old November 2nd, 2004, 10:44 AM
calibus calibus is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 126 calibus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 39 sec
Reputation Power: 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))
}

Reply With Quote
  #6  
Old November 2nd, 2004, 02:30 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,891 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1Folding Points: 338184 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 7 h 53 m 18 sec
Reputation Power: 1537
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...

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Need a little help with this


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway