jQuery code and variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Grego
    Mini Mivite

    • Apr 2014
    • 24

    #1

    jQuery code and variables

    How do I test to see if a string is contained in a url?

    &mvt:global:Product_Code;

    The string it pulls down is formatted as ProductCategory_productID; On pages where product category is TFC, I have special plans. (If you must know, I want to .addclass('hide this row') )

    Here I tryed to pass it into some jQuery code:

    Code:
    $( document ).ready(function() {
    
        var str = $("&mvt:global:Product_Code;");
    
        if (str.indexOf("TFC") >= 0) {
            alert('Do this stuff');
        }
    });
  • hmendenhall
    Mivite

    • Nov 2014
    • 108

    #2
    Re: jQuery code and variables

    Originally posted by Grego View Post
    How do I test to see if a string is contained in a url?

    &mvt:global:Product_Code;

    The string it pulls down is formatted as ProductCategory_productID; On pages where product category is TFC, I have special plans. (If you must know, I want to .addclass('hide this row') )

    Here I tryed to pass it into some jQuery code:

    Code:
    $( document ).ready(function() {
    
        var str = $("&mvt:global:Product_Code;");
    
        if (str.indexOf("TFC") >= 0) {
            alert('Do this stuff');
        }
    });

    Try this...

    <script type="text/javascript">
    $(document).ready(function () {
    var str = $("&mvt:global:Product_Code;");

    if(window.location.href.indexOf("TFC") > -1) {
    alert("Do this stuff");
    }
    });
    </script>
    Last edited by hmendenhall; 12-15-14, 04:40 PM.
    Happie Mendenhall
    Support Technician
    Miva, Inc.

    Comment

    • Grego
      Mini Mivite

      • Apr 2014
      • 24

      #3
      Re: jQuery code and variables

      That worked!

      So, I didn't really call a global, but instead, "window.location.href" calls the url directly, hence "var str" is not necessary.

      Comment

      Working...
      X