SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast mav's Avatar
    Join Date
    Feb 2003
    Location
    Miami, FL
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hidden form value and configurator price js

    I have this javascript for a computer configurator that does automatic price updates. It works with select manus but I need it to work with hidden tags as well. Here's the code...

    function showPrice(form)
    {
    var myTotalPrice = 0;
    var showUP = 0;
    var myMathProblem = "";
    myItemPrice = parseFloat(form.nuPrice.value);
    for (var i = 0; i < form.elements.length; i++)
    {
    var e = form.elements[i];
    if ( e.type == 'select-one' )
    {
    showUP = 1;
    Item = e.selectedIndex;
    myPrice = e.options[Item].text;
    myDollarSign = myPrice.indexOf("$",0)
    if ( myDollarSign != "-1" )
    {
    myParSign = myPrice.indexOf(")", myDollarSign);
    myAttributeString = myPrice.substring(myDollarSign+1, myParSign);
    myAttributeString = myAttributeString.replace(/,/,"");
    myAttributePrice = parseFloat(myAttributeString);
    myMathProblem = myPrice.charAt(myDollarSign - 1);
    } else { myAttributePrice = 0; }
    if (myMathProblem == "-")
    {
    myTotalPrice = myTotalPrice - myAttributePrice;
    } else {
    myTotalPrice = myTotalPrice + myAttributePrice;
    }
    }
    }
    if ( showUP )
    {
    myTotalPrice = FormatNumber(myTotalPrice + myItemPrice);
    document.getElementById("productNEWprice").innerHTML = "Subtotal Price with Options $" + myTotalPrice;
    }
    }

    I'm going crazy trying to get it to work with hidden form tags... please help. Thanks.

  2. #2
    SitePoint Enthusiast mav's Avatar
    Join Date
    Feb 2003
    Location
    Miami, FL
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This what I tried...

    function showPrice(form)
    {
    var myTotalPrice = 0;
    var showUP = 0;
    var myMathProblem = "";
    myItemPrice = parseFloat(form.nuPrice.value);
    for (var i = 0; i < form.elements.length; i++)
    {
    var e = form.elements[i];
    if ( e.type == 'select-one' )
    {
    showUP = 1;
    Item = e.selectedIndex;
    myPrice = e.options[Item].text;
    myDollarSign = myPrice.indexOf("$",0)
    }
    else if ( e.type == 'hidden' )
    {
    showUP = 1;
    myPrice = parseFloat(e.value);
    myDollarSign = myPrice.indexof("$",0)
    }
    if ( myDollarSign != "-1" )
    {
    myParSign = myPrice.indexOf(")", myDollarSign);
    myAttributeString = myPrice.substring(myDollarSign+1, myParSign);
    myAttributeString = myAttributeString.replace(/,/,"");
    myAttributePrice = parseFloat(myAttributeString);
    myMathProblem = myPrice.charAt(myDollarSign - 1);
    } else { myAttributePrice = 0; }
    if (myMathProblem == "-")
    {
    myTotalPrice = myTotalPrice - myAttributePrice;
    } else {
    myTotalPrice = myTotalPrice + myAttributePrice;
    }
    }
    }

    Gives me an error. The value I'm passing is formatted like this: +$10.00

  3. #3
    SitePoint Enthusiast mav's Avatar
    Join Date
    Feb 2003
    Location
    Miami, FL
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?


Bookmarks

Posting Permissions

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