We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    My head is on vacation today, I can’t figure this out:

    In a document I have first a UL list
    <ul id="a-z-list>
        <li><a href="">A</a></li>
        <li><a href="">B</a></li>
        <li><a href="">C</a></li>
        ...
        <li><a href="">X</a></li>
        <li><a href="">Y</a></li>
        <li><a href="">Z</a></li>
    </ul>


    And then I have a
    <DIV id="result"></div>


    And finally I have my Ditto-call
    [!Ditto? &parents=`369` &depth=`0` &display=`all` &sortBy=`pagetitle` &sortDir=`ASC` &extenders=`glossaryFilter` &filterBy=`[parameter transfered from the clicked link in the UL-list]` &tpl=`photoListSort` &hideFolders=`1`!]


    So, the question: How can I transfer the value from the selected link to the Ditto-call and then open the result in the same DIV#result with Jquery, every time, as an Ajax function? (Hmm, was that understandable. I think so. smiley)

    MODx Evolution 1.05.
    Jquery 1.4.4
      I think, thererfor I am! But what I am, and why...?
      • 29076
      • 615 Posts
      OK, I got to work as a standalone html-file with this code:
      <!DOCTYPE html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>A-z test</title>
      <style >
          ul { list-style:none; cursor:pointer; }
          li { display:block; float:left; width:30px; text-align:center; padding:0 5px 0 5px; border-right:1px solid #ccc; }
          li:hover { background:#ddd; }
          div.demo-container { clear:both; margin:30px; }
      </style>
      <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
      <script>
      $(document).ready(function()
      {
          $("#a-z-list li").click(function() {
                  var selected = $(this).html();
                  $('div#result').html(function() {
                    return '[!Ditto? &parents=`369` &depth=`0` &display=`all` &sortBy=`pagetitle` &sortDir=`ASC` &extenders=`glossaryFilter` &filterBy=`' + selected + '` &tpl=`photoListSort-Norsk` &hideFolders=`1`!]';
                  });
          });
      });
      </script>
      </head>
      <body>
          <ul id="a-z-list">
              <li>a-b</a></li>
              <li>c</a></li>
              <li>d</a></li>
              <li>e-f</a></li>
              <li>g-k</a></li>
          </ul><br />
          <div id="result">
              Demonstration Box
          </div>
      </body>
      </html>

      You can see it here: http://svalbardflora.net/a-z-list.html:
      But with
          <ul id="a-z-list">
              <li>a-b</a></li>
              <li>c</a></li>
              <li>d</a></li>
              <li>e-f</a></li>
              <li>g-k</a></li>
          </ul><br />
          <div id="result">
              Demonstration Box
          </div>
      in a MODx document and
      <script>
      $(document).ready(function()
      {
          $("#a-z-list li").click(function() {
                  var selected = $(this).html();
                  $('div#result').html(function() {
                    return '[!Ditto? &parents=`369` &depth=`0` &display=`all` &sortBy=`pagetitle` &sortDir=`ASC` &extenders=`glossaryFilter` &filterBy=`' + selected + '` &tpl=`photoListSort-Norsk` &hideFolders=`1`!]';
                  });
          });
      });
      </script>
      in the header it doesn’t work, see here: http://svalbardflora.net/index.php?id=1121. The template for the id=1121 is almost empty, it only loads the jquery-1.4.4.

      I also tried to change from $ to jquery, but then the script didn’t work at all, not even in the stand-alone file.

      Has anyone of you a suggestion on what I’m doing wrong here?
        I think, thererfor I am! But what I am, and why...?
        • 29076
        • 615 Posts
        It all comes down to the []. Jquery don’t return those brackets. I have to read some more jquery. tongue
          I think, thererfor I am! But what I am, and why...?
          • 26931
          • 2,314 Posts
          Hi Sylvaticus,

          not sure it will work that way, have a look at sottwells eForm/Ajax example: http://modxcms.com/forums/index.php?topic=43476.0

          you’d need to call the Ditto Snippet in a separate resource
          Create a document with no template (none). Give it an appropriate alias; this will be used later in the AJAX request. Something like ’shareform’ maybe. To avoid problems, I cleared all the Settings checkboxes except Published. I also cleared the Show in Menu checkbox.

          good luck smiley
            • 29076
            • 615 Posts
            Thanks sharkbait. So far this solution won’t work since I haven’t got friendly URLs to work on this site, and as far as I know jquery don’t open .php files.
              I think, thererfor I am! But what I am, and why...?