2 Replies Latest reply on Jul 11, 2018 9:00 AM by PotatoMan

    $(this) in dynamic action

    PotatoMan

      Hi

       

      I wanted to know if the following was possible.

       

      I've created a classic report querying some irrelevant data. Lets assume it's the following product table:

      Product_idProduct_name
      1Bread
      2Milk
      3Eggs
      4Apples
      5Bottled Water

       

      On the product_name column I've added a class: .productName

       

      I created a dynamic action with:


      event: click
      selection type: jQuery Selector

      jQuery Selector: .productName

       

      as shown below

       

      I then created a JavaScript true event wherein i'm trying to retrieve the text of the field clicked on as follows:

       

      var txt =$(this).text();

      alert(txt);

       

      I expected if I clicked on milk then 'Milk' would pop up in an alert box, and if I clicked on eggs then 'Eggs' would pop up and so on.

      However a blank alert box pops up.

       

      Is it not possible to use $(this) inside the dynamic action true event?

       

      Thanks

       

      Edit: wording

        • 1. Re: $(this) in dynamic action
          fac586

          PotatoMan wrote:

           

          Hi

           

          I wanted to know if the following was possible.

           

          I've created a classic report querying some irrelevant data. Lets assume it's the following product table:

          Product_id
          Product_name
          1Bread
          2Milk
          3Eggs
          4Apples
          5Bottled Water

           

          On the product_name column I've added a class: .productName

           

          I created a dynamic action with:


          event: click
          selection type: jQuery Selector

          jQuery Selector: .productName

           

          as shown below

           

          I then created a JavaScript true event wherein i'm trying to retrieve the text of the field clicked on as follows:

           

          var txt =$(this).text();

          alert(txt);

           

          I expected if I clicked on milk then 'Milk' would pop up in an alert box, and if I clicked on eggs then 'Eggs' would pop up and so on.

          However a blank alert box pops up.

           

          Is it not possible to use $(this) inside the dynamic action true event?

          Yes it is, but it doesn't make sense to do so because in this context this is a dynamic action object, not a DOM element. The clicked element can be accessed using the DA object's triggeringElement property. What you should be using in your code is $(this.triggeringElement).

          • 2. Re: $(this) in dynamic action
            PotatoMan

            Thank you