Announcement

Collapse
No announcement yet.

Posting a variable to javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Posting a variable to javascript

    For superpages, I need to pass the order id and order total variables to a script. I am currently using v5 and wondering how to go about doing this. Below is my code and seeing that the template tags do not render when within quotes. Any advice/help would be much appreciated.

    Thanks!

    HTML Code:
    <NOSCRIPT>
    <IMG HEIGHT="1" WIDTH="1"
    SRC="https://cust1259.bidcenter-27.superpages.com/18560599/marker/
    Revenue+1?js=no&Order=&mvt:order:id;&Total=&mvt:order:formatted_total;">
    </NOSCRIPT>
    
    <SCRIPT LANGUAGE="JavaScript"
    SRC="https://cust1259.bidcenter-27.superpages.com/tag.js"
    TYPE="text/javascript"></SCRIPT>
    <SCRIPT LANGUAGE="JavaScript">
    tag("cust1259.bidcenter-27.superpages.com","/18560599/marker/
    Revenue+1","Order","&mvt:order:id;","Total","&mvt:order:formatted_total;");
    </SCRIPT>

    #2
    Re: Posting a variable to javascript

    Hi: I pass variables to JS like this if they ate in a <form:
    <form method="post" onsubmit="return passvar(this)" action="&mvt:global:sessionurl;">
    <input type="hidden" name="Product_Name" value="&mvte:item:name;">
    </form>

    <script type="text/javascript">
    function passvar(obj) {
    var prod_name = obj.Product_Name.value;
    // then use the variable where ever you choose
    bla bla bla
    return true;
    } // end of JS function
    </script>

    Larry
    Larry
    Luce Kanun Web Design
    www.facebook.com/wajake41
    www.plus.google.com/116415026668025242914/posts?hl=en


    Comment


      #3
      Re: Posting a variable to javascript

      I've used mvt: entities inside JavaScript strings, like what you posted, and they work OK. I wonder if something else is wrong here. What page template are you putting this script on? Are you sure the "order" item is assigned to the page?
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Re: Posting a variable to javascript

        Thanks wajake41 I'll give it a try and see.

        Kent, it's on the invoice page. When the item is called in an image (1px X 1px) that is associated with the marker code the entities are filled in, but within the script they are not.

        The generated code is below.

        Thanks!!

        HTML Code:
        <!-- Runa Tracking Implementation -->
        
        
        
        <script language="JavaScript" type="text/javascript">
        
        //<![CDATA[
        
        
        
         var merchant_config = {
        
           merchant_id: "60a72705-8468-ac40-0153-4b9e9da5d8c3",
        
           merchant_type: "miva",
        
           merchant_version: "5.0.1.7",
        
           merchant_host: "http://hydroponicsunlimited.com/mm5/",
        
           runa_base_url: "//cheshire-production.runa.com",
        
           merchant_cart_url: "http://hydroponicsunlimited.com/mm5//merchant.mvc?Screen=BASK&Store_Code=PH",
        
           runa_cid: "",
        
           site_cid: ""
        
         };
        
        
        
        var runa_all_js  = merchant_config.runa_base_url + "/client/boot/etailer/miva/" + merchant_config.merchant_id ;
        
        function start_runa_client(){
        
          var element = document.createElement("script");
        
          element.src = runa_all_js;
        
          element.type = "text/javascript";
        
          document.body.appendChild(element);
        
        }
        
        
        
        (function(i) {
        
         var u = navigator.userAgent.toLowerCase();
        
         var ie = /*@cc_on!@*/false;
        
         if (/webkit/.test(u)) {
        
           // safari
        
           timeout = setTimeout(function(){
        
        if ( document.readyState == "loaded" || 
        
        document.readyState == "complete" ) {
        
        i();
        
        } else {
        
         setTimeout(arguments.callee,10);
        
        }
        
        }, 10); 
        
         } else if ((/mozilla/.test(u) && !/(compatible)/.test(u)) ||
        
                    (/opera/.test(u))) {
        
           // opera/moz
        
           document.addEventListener("DOMContentLoaded",i,false);
        
         } else if (ie) {
        
           // IE
        
           (function (){ 
        
             var tempNode = document.createElement("document:ready"); 
        
             try {
        
               tempNode.doScroll("left"); 
        
               i(); 
        
               tempNode = null; 
        
             } catch(e) { 
        
               setTimeout(arguments.callee, 0); 
        
             } 
        
           })();
        
         } else {
        
           window.onload = i;
        
         }
        
        })(start_runa_client);
        
        
        
        //]]>
        
        </script>
        
        
        
        
        
        <!-- Runa Tracking Implementation Ends -->
        
        </body> 
        <NOSCRIPT>
        <IMG HEIGHT="1" WIDTH="1"
        SRC="https://cust1259.bidcenter-27.superpages.com/18560599/marker/
        Revenue+1?js=no&Order=1424&Total=$9.00">
        </NOSCRIPT>
        <SCRIPT LANGUAGE="JavaScript"
        SRC="https://cust1259.bidcenter-27.superpages.com/tag.js"
        TYPE="text/javascript"></SCRIPT>
        <SCRIPT LANGUAGE="JavaScript">
        tag("cust1259.bidcenter-27.superpages.com","/18560599/marker/
        Revenue+1","Order","&mvt:order:id;","Total","&mvt:order:formatted_total;");
        </SCRIPT>

        Comment


          #5
          Re: Posting a variable to javascript

          I just checked the code from a recent custom job. Try using the old convention of putting HTML comment markers inside the script tag, e.g.
          Code:
          <script language="javascript">
          <!--
          .... your code here ....
          // -->
          </script>
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Re: Posting a variable to javascript

            @wajake41, for the form method, should I add this to the payment page or can this be inserted into the invoice page. I see that it is onsubmit, so thinking that it has to be in the payment page.

            Thanks!!

            Comment

            Working...
            X