We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11121
    • 79 Posts
    I have a typical getresources page with a list of some resources. My problem is that I want to display one tv, only when you are pressing a button.

    Here is the link (you must login first, facebook login supported):
    http://dogmatch.gr/index.php?id=106

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      The usual way to do that would be with an Ajax call to a processor that retrieved the TV and displayed it with JavaScript. You could do it with or without JQuery, though JQuery would make it easier and you could easily have some fade or slide effects.

      It would only be easy if you're getting the TV value for the current page. It should be possible to do it with a multiple buttons created by getResources or pdoResources, but it would be a little trickier.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 11121
        • 79 Posts
        Quote from: BobRay at May 11, 2015, 06:45 PM
        The usual way to do that would be with an Ajax call to a processor that retrieved the TV and displayed it with JavaScript. You could do it with or without JQuery, though JQuery would make it easier and you could easily have some fade or slide effects.

        It would only be easy if you're getting the TV value for the current page. It should be possible to do it with a multiple buttons created by getResources or pdoResources, but it would be a little trickier.


        Well, I don't have specific page for each resource so I need multiple buttons...

        The problem is that I have not knowledge of Ajax. I must read...
          • 3749
          • 24,544 Posts
          I'm assuming that you want to show the content of a TV for each resource when a button is clicked in the listing for that resource.

          If you don't mind having the value of the TV in the source code (HTML) of the page, you could do it without Ajax.

          Just put the TV in your Tpl chunk inside a hidden div, with an onCick event for its button that calls a JavaScript function that shows it. (This is off the top of my head and untested, but should get you started.)

          <div id=tv[+idx] style="display:none">
          [[*TvName]]
          </div] 
          
          <input id="clickMe" type="button" value="Show me the TV" onclick="showTv(tv[+idx]);" />
          


          JS (put this in the template or the page content):
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
          
          <script type="text/javascript">
          function showTv(id) {
              $("#" + id).show("slow");
          }
          </script>
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 11121
            • 79 Posts
            Thank you for your suggestion. I don't have problem to have the hidden info in html code *.

            I put extra brackets to get idx.

            Quote from: BobRay at May 12, 2015, 02:32 PM


            <div id=tv[[+idx]] style="display:none">
            [[+TvName]]
            </div] 
             
            <input id="clickMe" type="button" value="Show me the TV" onclick="showTv(tv[[+idx]]);" />
            
            


            JS (put this in the template or the page content):
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
            
            <script type="text/javascript">
            function showTv(id) {
                $("#" + id).show("slow");
            }
            </script>
            </div>


            But the script is not working. Obviously it cannot take the correct idx.

            Any ideas how I could generate correct idx in the script? I have multiple buttons to a getresource list.

            The first part is working perfect. Every button gets its own # and id button value. But how I make the script to work for all off them?

            For one item the problem is solved.


            * In second thought, a solution without data showing in html at beginning would be perfect.

            [ed. note: gordonas last edited this post 11 years, 5 months ago.]
            • discuss.answer
              • 3749
              • 24,544 Posts
              My mistake. It should be:

              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
               
              <script type="text/javascript">
              function showTv(id) {
                  $("#tv" + id).show("slow");
              }
              </script>
              

              [ed. note: BobRay last edited this post 11 years, 4 months ago.]
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 11121
                • 79 Posts
                Finally I made a page for every ad and solve the problem. Thank you!