Skip navigation
Currently Being Moderated

What is not right about this code??

Mar 25, 2013 7:07 AM

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);

 
Replies
  • Currently Being Moderated
    Mar 25, 2013 8:05 AM   in reply to Ness_quick

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 8:05 AM   in reply to Ness_quick

    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/

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 8:26 AM   in reply to kennethkawamoto2

    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);

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 8:40 AM   in reply to Ness_quick

    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)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 8:53 AM   in reply to Ness_quick

    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);

     
    |
    Mark as:
  • Sudarshan Thiagarajan
    4,000 posts
    Oct 15, 2010
    Currently Being Moderated
    Mar 25, 2013 9:07 AM   in reply to Ness_quick

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 25, 2013 1:19 PM   in reply to Ness_quick

    Try:

    total_funeral = 1640.00 + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76922) ) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_00005) ) + Number(getSelectedValueFromSelectList(document.catwebformform22057.CA T_Custom_00015)) + Number(GetSelectedItem(document.catwebformform22057.CAT_Custom_76926) ) + (document.getElementById('CAT_Custom_76926_0').checked ? Number(getSelectedValueFromSelectList(document.catwebformform22057.CA T_Custom_00010)) : 0) + Number(getSelectedValueFromSelectList(document.catwebformform22057.CA T_Custom_76927));

     

    function getSelectedValueFromSelectList (element) {

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

    }

    --

    Kenneth Kawamoto

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 4:31 AM   in reply to Ness_quick

    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!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points