SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't change a var to accept more than one character input

    Hi,

    I'm trying to implement a OSC addon to update the options price in realtime from www.oscommerce.com/community/contributions,1385, but it seems to only work with single characters currency symbols, like $, €, £, etc. any symbol that as more than one character, like Brazil Real R$, or C€, or Svenska Kronor Skr, doesn't work and the price doesn't update, it stays R$ 0.00 whatever options you choose.

    I need to use this contribution with the Brazil Real symbol at the left of price like R$ 999.00.
    Also I can't make it work like 10.000,00. It only works like 10,000.00. But this point is not so important.

    I have tried everything for some days, but I don't know javascript.

    Anyone looking at the javacript code could spot what I have to change.

    Thank you very much in advance.

    Here is the code:

    Code:
    <script language="javascript">
    <!--
       function FormatNumber(num)
       {
         if(isNaN(num)) { num = "0"; }
         sign = (num == (num = Math.abs(num)));
         num = Math.floor(num*100+0.50000000001);
         cents = num&#37;100;
         num = Math.floor(num/100).toString();
         if(cents<10) { cents = "0" + cents; }
         for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
         {
           num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
         }
         return (((sign)?'':'-') + num + '.' + cents);
       }
    
         function FormatNumber1(num)
      {
        if(isNaN(num)) { num = "0"; }
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*1+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10) { cents = "0" + cents; }
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        {
          num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
        }
        return (((sign)?'':'-') + num + ',' + cents);
      }
    
      function showPrice(form)
      {
       var currencysymbol1 = "";
        var currencysymbol2 = "";
        var myTotalPrice = 0;
        var showUP = 0;
        var myMathProblem = "";
        myItemPrice = parseFloat(form.nuPrice.value);
    
       myDollarSign2 = form.nuPrice.value.indexOf("EUR",0)
       if ( myDollarSign2 != "-1" )
       {
          currencysymbol1 = "";
         currencysymbol2 = " EUR";
       } else {
         currencysymbol1 = "R$";
         currencysymbol2 = "";
       }
    
       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("R$",0)
            if ( myDollarSign != "-1" )
            {
            currencysymbol1 = "R$";
            currencysymbol2 = "";
              myParSign = myPrice.indexOf(")", myDollarSign);
              myAttributeString = myPrice.substring(myDollarSign+1, myParSign);
              myAttributeString = myAttributeString.replace(/,/,"");
              myAttributePrice = parseFloat(myAttributeString);
              myMathProblem = myPrice.charAt(myDollarSign - 1);
            } else {
             myDollarSign1 = myPrice.indexOf("(",0)
             if ( myDollarSign1 != "-1" )
             {
             currencysymbol1 = "";
              currencysymbol2 = " EUR";
             myParSign = myPrice.indexOf(")", myDollarSign1);
             myAttributeString = myPrice.substring(myDollarSign1+1, myParSign);
             myAttributeString = myAttributeString.replace(/,/,"");
             myAttributePrice = parseFloat(myAttributeString);
             myMathProblem = myPrice.charAt(myDollarSign1 - 1);
             } else {
             myAttributePrice = 0;
             }
         
          }
              if (myMathProblem == "-")
              {
                myTotalPrice = myTotalPrice - myAttributePrice;
              } else {
                myTotalPrice = myTotalPrice + myAttributePrice;
              }
          }
        }
        if ( showUP )
        {
          myDollarSign3 = form.nuPrice.value.indexOf(".",0)
          if ( myDollarSign3 != "-1" )
          {
            myTotalPrice = FormatNumber(myTotalPrice + myItemPrice);
          } else {
            myTotalPrice = FormatNumber1(myTotalPrice + myItemPrice);
          }
            document.getElementById("productNEWprice").innerHTML = currencysymbol1 + myTotalPrice + currencysymbol2;
        }
      }
    
        function showPrice1(form)
      {
       var currencysymbol1 = "";
        var currencysymbol2 = "";
        var myTotalPrice = 0;
        var showUP = 0;
        var myMathProblem = "";
        myItemPrice = parseFloat(form.nuPrice1.value);
    
       myDollarSign2 = form.nuPrice1.value.indexOf("EUR",0)
       if ( myDollarSign2 != "-1" )
       {
          currencysymbol1 = "";
         currencysymbol2 = " EUR";
       } else {
         currencysymbol1 = "R$";
         currencysymbol2 = "";
       }
    
       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" )
            {
            currencysymbol1 = "R$";
            currencysymbol2 = "";
              myParSign = myPrice.indexOf(")", myDollarSign);
              myAttributeString = myPrice.substring(myDollarSign+1, myParSign);
              myAttributeString = myAttributeString.replace(/,/,"");
              myAttributePrice = parseFloat(myAttributeString);
              myMathProblem = myPrice.charAt(myDollarSign - 1);
            } else {
             myDollarSign1 = myPrice.indexOf("(",0)
             if ( myDollarSign1 != "-1" )
             {
             currencysymbol1 = "";
              currencysymbol2 = " EUR";
             myParSign = myPrice.indexOf(")", myDollarSign1);
             myAttributeString = myPrice.substring(myDollarSign1+1, myParSign);
             myAttributeString = myAttributeString.replace(/,/,"");
             myAttributePrice = parseFloat(myAttributeString);
             myMathProblem = myPrice.charAt(myDollarSign1 - 1);
             } else {
             myAttributePrice = 0;
             }
         
          }
              if (myMathProblem == "-")
              {
                myTotalPrice = myTotalPrice - myAttributePrice;
              } else {
                myTotalPrice = myTotalPrice + myAttributePrice;
              }
          }
        }
        if ( showUP )
        {
          myDollarSign3 = form.nuPrice1.value.indexOf(".",0)
          if ( myDollarSign3 != "-1" )
          {
            myTotalPrice = FormatNumber(myTotalPrice + myItemPrice);
          } else {
            myTotalPrice = FormatNumber1(myTotalPrice + myItemPrice);
          }
            document.getElementById("productNEWprice1").innerHTML = currencysymbol1 + myTotalPrice + currencysymbol2;
        }
      }
    //-->
    </script>
    And there is this code too:

    PHP Code:
                <?php 
                    
    if(tep_has_product_attributes($product_info['products_id'])){ 
                        if (
    $new_price tep_get_products_special_price($product_info['products_id'])) {
                            
    ?> 
                            <script type="text/javascript">document.write('<s><div id="productNEWprice1"></div>\n</s>');</script>
                            <script type="text/javascript">document.write('<span class="productSpecialPrice"><div id="productNEWprice"></div>\n</span>');</script>
                            <noscript><?php echo $products_price?></noscript>
                            <?php } else {?>
                            <script type="text/javascript">document.write('<div id="productNEWprice"></div>\n</span>');</script>
                            <noscript><?php echo $products_price?></noscript>
                            <?php }
                     } else { 
                         echo 
    $products_price; } ?>
                
                </td>
              <input type="hidden" name="nuPrice" value="<?php echo str_replace("$","",$nuPrice); ?>">
              <input type="hidden" name="nuPrice1" value="<?php echo str_replace("$","",$nuPrice1); ?>">

  2. #2
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean:

    Anyone looking at the javacript code could spot what I have to change ?


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
  •