16 Replies Latest reply: Mar 26, 2013 4:31 AM by kennethkawamoto2 RSS

    What is not right about this code??

    Ness_quick Community Member

      Can anyone tell me what is not right about this code??? Ive have been trying to work it out for myself for the past 2hrs but cant seem to get it right. I think i must have a bracket or something in the wrong place or missing but whatever i do it either flags up as an alert or wont calculate once uploaded. Sooooo frustrating!!

       

      total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00015.value) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010)) + Number(document.catwebformform22057.CAT_Custom_76927.value) + (document.getElementById('CAT_Custom_76926_0').checked ? Number(document.catwebformform22057.CAT_Custom_00010.value) : 0);

        • 1. Re: What is not right about this code??
          MurraySummers ACP/MVPs

          You are missing the .value bit on several of the expressions.

          • 2. Re: What is not right about this code??
            kennethkawamoto2 Community Member

            This:

            GetSelectedItem(document.catwebformform22057.CAT_Custom_00015. value)

            I guess it should be

            GetSelectedItem(document.catwebformform22057.CAT_Custom_00015)

            --

            Kenneth Kawamoto

            http://www.materiaprima.co.uk/

            • 3. Re: What is not right about this code??
              MurraySummers ACP/MVPs

              Try this -

               

              total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00015)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010) ) + Number(document.catwebformform22057.CAT_Custom_76927)) + (document.getElementById('CAT_Custom_76926_0').checked ? Number(document.catwebformform22057.CAT_Custom_00010.value) : 0);

              • 4. Re: What is not right about this code??
                Ness_quick Community Member

                Does the '.value' only need to be applied to drop down menus? Is this is correct there are only three dropdown menus on that part of the form which are 'Additional services' - CAT_Custom_00010, ' Number of limousines' - CAT_Custom_76927 and ' Use of vintage hearse' - CAT_Custom_00015. which ive applied the '.value' to but still doesnt work?

                 

                total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00005)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010.value) ) +

                (Number(document.catwebformform22057.CAT_Custom_76927.value)) + (document.getElementById('CAT_Custom_76926_0').checked ? Number(document.catwebformform22057.CAT_Custom_00010.value) : 0);  + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00015.value) )

                • 5. Re: What is not right about this code??
                  Ness_quick Community Member

                  Tried that code but its flagging up red alert!

                  • 6. Re: What is not right about this code??
                    MurraySummers ACP/MVPs

                    What does the alert say?

                     

                    The GetSelectedItem function returns a value, so those calls do not need to be explicit with regard to value. The only element that would need the value us the last one and even that could be changed to this -

                     

                    (document.getElementById('CAT_Custom_76926_0').checked ? Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010)) : 0)

                     

                    (that trailing semicolon shouldn't be there - please remove it from either expression)

                    • 8. Re: What is not right about this code??
                      MurraySummers ACP/MVPs

                      Sheesh.

                       

                      Try this -

                       

                      total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00015) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010) ) +

                      Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76927) ) +

                      (document.getElementById('CAT_Custom_76926_0').checked ? Number(document.catwebformform22057.CAT_Custom_00010.value) : 0);

                      • 9. Re: What is not right about this code??
                        Ness_quick Community Member

                        So its working than it was! Everthing is working apart from- CAT_Custom_76927 ( number of limousines), CAT_Custom_00015 (use of vintage hearse).

                         

                        And the CAT_Custom_00005 (carry in night before) isnt calculating into the total?

                        • 10. Re: What is not right about this code??
                          sudarshan.t MVP

                          Use this website to lint your code and to check for any errors/ exceptions: http://www.jslint.com/

                          • 11. Re: What is not right about this code??
                            Ness_quick Community Member

                            Its just these two that wont calculate -

                             

                            CAT_Custom_00015 and CAT_Custom_76927

                             

                            Just cant see why?

                            • 12. Re: What is not right about this code??
                              Ness_quick Community Member

                              This is all of javascript for caculation (http://www.milesmemorials.com/estimator.html) -

                               

                              function GetSelectedItem(frname) {

                               

                               

                              chosen = ""

                              len = frname.length

                               

                               

                              for (i = 0; i <len; i++) {

                              if (frname[i].checked) {

                              chosen = frname[i].value

                              }

                              }

                              return chosen

                              }

                              function Recalculate() {

                               

                               

                              total_funeral = ""

                              crem_disbursements = ""

                              burial_disbursements = ""

                              total_disbursements = ""

                              doctors_fees = ""

                              crem_fee = ""

                              cemetery_fee = ""

                              minister_fee_crem = ""

                              minister_fee_burial = ""

                              civil_fee_crem = ""

                              civil_fee_burial = ""

                              carry_fee_burial = ""

                               

                               

                               

                               

                              total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00005)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00015.value)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00010.value)) +

                              Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76927.value))  +

                              (document.getElementById('CAT_Custom_76926_0').checked ? Number(document.catwebformform22057.CAT_Custom_00010.value) : 0);

                               

                               

                              minister_fee_crem = Number(document.catwebformform22057.CAT_Custom_00003.value)

                              minister_fee_burial = Number(document.catwebformform22057.CAT_Custom_00004.value)

                              civil_fee_crem = Number(document.catwebformform22057.CAT_Custom_00006.value)

                              civil_fee_burial = Number(document.catwebformform22057.CAT_Custom_00001.value)

                              carry_fee_burial = Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00005))

                              doctors_fees = Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76929))

                              crem_fee = Number(document.catwebformform22057.CAT_Custom_76930.value)

                              cemetery_fee = Number(document.catwebformform22057.CAT_Custom_76931.value)

                               

                               

                              zz=document.getElementById('CAT_Custom_76926_0').checked==true;if(zz) { document.getElementById('basicServices').style.display='block'; } else { document.getElementById('basicServices').style.display='none'; };

                               

                               

                               

                               

                              crem_disbursements = civil_fee_crem + doctors_fees + crem_fee + minister_fee_crem

                              burial_disbursements = minister_fee_burial + cemetery_fee + civil_fee_burial

                               

                               

                              if(Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76928)) == 0){

                                        total_disbursements = crem_disbursements;

                              }else{

                                        total_disbursements = burial_disbursements;

                              }

                               

                               

                              if(Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926)) == 0){

                                        CAT_Custom_00010.value=0

                              }

                               

                               

                              document.catwebformform22057.total.value = total_funeral.toFixed(2);

                              document.catwebformform22057.doctors_fees.value = doctors_fees.toFixed(2);

                              document.catwebformform22057.civil_fee_crem.value = civil_fee_crem.toFixed(2);

                              document.catwebformform22057.civil_fee_burial.value = civil_fee_burial.toFixed(2);

                              document.catwebformform22057.minister_fee_crem.value = minister_fee_crem.toFixed(2);

                              document.catwebformform22057.minister_fee_burial.value = minister_fee_burial.toFixed(2);

                              document.catwebformform22057.carry_fee_burial.value = carry_fee_burial.toFixed(2);

                              document.catwebformform22057.crem_fee.value = crem_fee.toFixed(2);

                              document.catwebformform22057.cemetery_fee.value = cemetery_fee.toFixed(2);

                              document.catwebformform22057.total_crem_disbursements.value = crem_disbursements.toFixed(2);

                              document.catwebformform22057.total_burial_disbursements.value = burial_disbursements.toFixed(2);

                              document.catwebformform22057.grand_total.value = (total_funeral + total_disbursements).toFixed(2);

                              }

                              • 13. Re: What is not right about this code??
                                kennethkawamoto2 Community Member

                                Try:

                                total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00005)) + Number(getSelectedValueFromSelectList(document.catwebformform22057.CAT_Custom_00015)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926)) + (document.getElementById('CAT_Custom_76926_0').checked ? Number(getSelectedValueFromSelectList(document.catwebformform22057.CAT_Custom_00010)) : 0) + Number(getSelectedValueFromSelectList(document.catwebformform22057.CAT_Custom_76927));

                                 

                                function getSelectedValueFromSelectList (element) {

                                    return element.options[element.selectedIndex].value;

                                }

                                --

                                Kenneth Kawamoto

                                http://www.materiaprima.co.uk/

                                • 14. Re: What is not right about this code??
                                  Ness_quick Community Member

                                  OK so i tried that but it flagged up red (please see image below).  I uploaded it anyway just to see what happens but now nothing calculates?

                                  screenshot.jpg

                                  • 15. Re: What is not right about this code??
                                    Ness_quick Community Member

                                    Its working, there were a few spaces which were a result of copying and pasting but now fixed!! Thank you!!

                                    • 16. Re: What is not right about this code??
                                      kennethkawamoto2 Community Member

                                      I don't get any reds and your site is working fine for me...?

                                       

                                      --

                                      Kenneth Kawamoto

                                      http://www.materiaprima.co.uk/

                                       

                                      Message was edited by: kennethkawamoto2 OK, good!