Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Issue with JS...first post and I appreciate any help

    I have created a quick little pricing engine to price some of the products that we sell. I was able to use a nice template online and it worked for most of what we offer. However, I needed to add a few filters and while doing so, needed to tweak the JS even further than I was originally comfortable with doing.

    Long story short, here is the main pricing page - www.pricemyleads.com - and this is the page in question as of now - www.pricemyleads.com/taxaged.html

    The js file for this page is - http://www.pricemyleads.com/js/taxag...alculations.js

    Any help is greatly appreciated. You'll see the issue when you start clicking on the check boxes.

    Thanks,

    brmacdon

  • #2
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Hi there,

    This is the first few thing I think you should change before I can go any further. Please try to replace:

    PHP Code:
    var selectedFilling theForm.elements["filling"]; 
    By:

    PHP Code:
    var selectedFilling document.getElementById("filling"); 
    And please do the same with the rest if you have any similar code. The problem may be there, try to insert alert() after that line to see if it returns the value you expected.

    Regards,

    Tim._

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cuzMazn View Post
    Hi there,

    This is the first few thing I think you should change before I can go any further. Please try to replace:

    PHP Code:
    var selectedFilling theForm.elements["filling"]; 
    By:

    PHP Code:
    var selectedFilling document.getElementById("filling"); 
    And please do the same with the rest if you have any similar code. The problem may be there, try to insert alert() after that line to see if it returns the value you expected.

    Regards,

    Tim._
    That did not fix it, but I just noticed something. If you choose a quantity and then precede to check every filter it then will display the cost correctly without any of this - "Total Price For Each Lead $0.2[object HTMLInputElement]0.81[object HTMLInputElement]0.030.060.09"
    Last edited by brmacdon; 01-23-2012 at 06:59 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,799
    Thanks
    78
    Thanked 4,410 Times in 4,375 Posts
    cuzMazn gave bad advice.

    If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

    There are so many things wrong with that code that I would just start over.

    Just for starters, look here:
    Code:
    var aged30=0;
    //Get a refernce to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkbox id="includeinscription"
    var aged30 = theForm.elements["aged30"]; 
    //If they checked the box set inscriptionPrice to 20
    if(aged30.checked==true){
        aged30=.00;
    }
    //finally we return the inscriptionPrice
    return aged30;
    You are using the SAME VARIABLE to refer to the element as you are using to get the value.

    So if the box is *NOT* checked, you are returning a reference to the checkbox *INSTEAD* of a number.

    And you haven't provide a lookup value for "None", so any unchecked box is returning a value of undefined.

    And and...

    I really would start over, were I you.

    It's ugly to use a piece of code designed for something different. The comments in the code make no sense and you aren't covering all the cases.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    brmacdon (01-23-2012)

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    cuzMazn gave bad advice.

    If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

    There are so many things wrong with that code that I would just start over.

    Just for starters, look here:
    Code:
    var aged30=0;
    //Get a refernce to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkbox id="includeinscription"
    var aged30 = theForm.elements["aged30"]; 
    //If they checked the box set inscriptionPrice to 20
    if(aged30.checked==true){
        aged30=.00;
    }
    //finally we return the inscriptionPrice
    return aged30;
    You are using the SAME VARIABLE to refer to the element as you are using to get the value.

    So if the box is *NOT* checked, you are returning a reference to the checkbox *INSTEAD* of a number.

    And you haven't provide a lookup value for "None", so any unchecked box is returning a value of undefined.

    And and...

    I really would start over, were I you.

    It's ugly to use a piece of code designed for something different. The comments in the code make no sense and you aren't covering all the cases.
    Just by changing the items in red, its fixed!! I dont know JS all that well and am basically just trying to patch something together! Thank you soooo much!!!!

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    One last question...how do I assign a negative number to a var?

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,078
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by brmacdon View Post
    One last question...how do I assign a negative number to a var?
    Is it not obvious?

    var mynumber = -12;

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    brmacdon (01-23-2012)

  • #8
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Is it not obvious?

    var mynumber = -12;
    Ha, I swear I tried the common sense answer, uploaded the file and it didn't work. Now, of course, it works fine THANKS!!

  • #9
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Coming together and I thank everyone that has helped!

    With just about every filter, it kicks back something like this (which is what I want):

    "Total Price For Each Record $0.23"

    But, for only a few, it shows too many decimal places:

    "Total Price For Each Record $0.21000000000000002"

    Any ideas?

  • #10
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Old Pedant View Post
    cuzMazn gave bad advice.

    If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

    ...
    Hi,

    Sorry about that, I didn't read the code completely and I was mistaken the name for the ID.

    Tim._

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,799
    Thanks
    78
    Thanked 4,410 Times in 4,375 Posts
    Quote Originally Posted by brmacdon View Post
    With just about every filter, it kicks back something like this (which is what I want):

    "Total Price For Each Record $0.23"
    Just use total.toFixed(2)

    That is, something like

    Code:
    var message = "Total Price for Each Record $" + total.toFixed(2);
    Adjust that to use your own actual variable names, of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    brmacdon (01-24-2012)

  • #12
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Just use total.toFixed(2)

    That is, something like

    Code:
    var message = "Total Price for Each Record $" + total.toFixed(2);
    Adjust that to use your own actual variable names, of course.
    Worked!! Thank you very much. This site is done and deployed! You may close this page if you'd like, mods!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •