#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171

    Onclick change function arguments value?


    Hi I am not sure how to do this.

    I want to load 'Next Photo' onclick. You know? Update the div using jquery, send the photo id and property id, run the query and show the next picture. This is the example. Mouse over the second box (The Moorings) for arrows to appear.

    I just thought I do something like this:
    Code:
    onclick="next_photo('<?php echo $row['hotel_id'];?>','<?php echo $row['photo_id'];?>');"
    But the problem with this is that when I update the first time, I somehow need to update the value of second argument so next tiem I click next, it goes to the right photo.
    Any ideas?

    Or maybe in general this can be achieved by another solution?

    Thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    Sydney Australia
    Posts
    189
    Rep Power
    84
    Originally Posted by zxcvbnm
    Hi I am not sure how to do this.


    Any ideas?


    Thank you
    When your ajax updates the div containing the photo, it needs to also update the div or span containing the "Next Photo" link.
  4. #3
  5. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Sigh.. I don't currently have examples of my own code to reference, to provide you with an exact example, but in pseudo-code-speak, this is one option:

    Code:
    <script type="text/javascript">
      var nextPage = ?; // Populate this first on initial PHP page load
      function nextImage(){
        // Perform AJAX call for "nextPage"
        // Have AJAX response include data for new image AND new next page
        nextPage = ajax.nextPage;
        // [Code to update currently displayed image]
      }
    </script>
    If that makes sense, you're making the inline onclick Javascript a littler dumber and moving all the logic into the function. And in the function, the nextImage is updated upon every click.

    This might not be the best solution, but it's the one I thought of first.
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171
    Thank you. I came up with the same solution menitoned above. A little too much work but works fine! Parts:
    Code:
    function show_next_photo(hotel_id, photo, main)
    	{
    		$.post('reloads/next_photo.php', { photo: photo, hotel_id: hotel_id, main: main },function(output){$('#hotel_photo_id' + hotel_id).html(output).show('slow');});
    	}

IMN logo majestic logo threadwatch logo seochat tools logo