Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    New Coder
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I figured the function wasn't seeing the new content, but I wasn't sure how to attach it. I don't know if I'm putting the suggested code blocks in the wrong places, but I can't get them to work.

    Early on, I noticed that if I put your attachAll function at the beginning of the page, it didn't work, but if I put it at the end, it found all the elements. Is there a way to have the browser re-read that part of the page when a button is clicked? I've been Googling and finding some stuff related to calling functions after an AJAX load, but not enough for me to understand it. I've also found the ".on" method, which can handle elements that are created after the page loads, but I'm not sure how to use it, since the highlighting function is in Javascript rather than jQuery.

    I actually just tried making a new .load button to get the highlighting script to replace itself with the exact same content (from a separate file) to see if the browser parses it then, but it didn't work.

    How would you load new table content? Using an AJAX .load was the only way I found, and I figured I'd try it myself before bothering anyone. Clearly, though, it doesn't play well with the other stuff I'm using (namely, the highlighting function you gave me). Is there a better way to do it, that won't break the highlighting function, in Javascript or any language/method?

    I also would have liked to be able to load the new content with drop down menus rather than dozens of buttons, but I couldn't figure out how. It doesn't affect the core functionality, though, so I'm focusing on just getting the page to work.

    So:

    1. Is there a way to just tell the browser to re-parse part of the page again? It could happen automatically when the user loads new content, or it could be a separate button, I don't mind.
    2. Should I just be loading the new content in a different way?

  2. #17
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    ??? Did you try the code I gave you in my post #14??

    Especially the basic version:
    Code:
    $("#i3guitar").click(
        function()
        { 
            $("#instrument3").load(
                "instrumentschromesafari/guitar.txt",
                "",
                function( ) { attachAll("instrument3"); }
            );  
        }
    );
    I don't see why that wouldn't work.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  3. #18
    New Coder
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I tried that, and as far as I can figure, all it does is break every .load on the page.

  4. #19
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Well, then I probably read the jQuery docs wrong, because there's no theoretical reason that I can see that it won't work. You might need to ask in the jQuery forum.

    Or wait...here's a HACK trick that *might* work:
    Code:
    $("#i3guitar").click(
        function()
        { 
            $("#instrument3").load("instrumentschromesafari/guitar.txt");
            setTimeout( function( ) { attachAll("instrument3"); }, 1000 );
        }
    );
    That will do the attachAll after waiting 1 second after the load starts. That's not a good idea for the final version, because it could take longer than 1 second for the load to occur, but it's worth trying as a test.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  5. #20
    New Coder
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    That didn't seem to work either.

    Should I ask in AJAX and Design, or Javascript frameworks?

  6. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    OH DOUBLE DOH ON ME!!!

    Of course you can't call attachAll( ) from the load() !!

    attachAll( ) is *ONLY* visible inside that anonymous function!!!

    Let's just get rid of the anonymous function. In other words, the end of the page should look like this:
    Code:
    <script type="text/javascript">
          function attachAll( inTable )
          {
              var pix = document.getElementById(inTable).getElementsByTagName("img");
              for ( var p = 0; p < pix.length; ++p ) 
              { 
                  var pic = pix[p];
                  pic.onmouseover = doMouseOver;
                  pic.onmouseout  = doMouseOut;
                  pic.setAttribute("originalSrc",pic.src);
              }
          }
          attachAll("instrument1");
          attachAll("instrument2");
          attachAll("instrument3");
          attachAll("treble1");
          attachAll("treble2");
          attachAll("treble3");
          attachAll("treble4");
          attachAll("bass1");
          attachAll("bass2");
          attachAll("bass3");
          attachAll("bass4");
          
          function doMouseOver( )
          {
              var pix = document.getElementsByName(this.name);
              for ( var p = 0; p < pix.length; ++p )
              {
                  pix[p].src = "blue.png";
              }
          }
          function doMouseOut( )
          {
              var pix = document.getElementsByName(this.name);
              for ( var p = 0; p < pix.length; ++p )
              {
                  pix[p].src = pix[p].getAttribute("originalSrc");
              }
          }
    </script>
    </body>
    </html>
    And *THEN* try calling attachAll("instrument3") [or whatever] as part of the load(), as in my prior messages.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. Users who have thanked Old Pedant for this post:

    TigerhawkT3 (09-04-2013)

  8. #22
    New Coder
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Oh, well of COURSE they're only visible inside the anonymous function! I knew that, and was just waiting for you to see it.

    >.>

    In all seriousness, thank you so much. That allowed me to fix everything, which is all completely functional now.

    For Chrome and Safari: http://www.tigerhawkt3.com/dviice/dv...safari-v2.html
    For all browsers: http://tigerhawkt3.com/dviice/dviice...bility-v2.html

    I recommend clearing your cookies/cache before visiting again, as it'll try using old instruments that had errors in them rather than the corrected versions I replaced them with.

    I hope you don't mind that I mentioned you in a commented section of the source code. If you want me to take that out, or use a different name or something, let me know.

    I'm going to give this "Thank User" feature a try.

  9. #23
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Hey, it was my fault: I was being fancy, putting the code in that anonymous function. And then forgetting that I had done so. It was a huge face-palm moment when I realized I'd been leading you around in circles. So thanks for saying thanks, considering it was my bug.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  10. #24
    New Coder
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Still, you solved it. Without your help, V2 wouldn't have happened. So thank you.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •