June 17th, 2013, 11:24 PM
-
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
June 17th, 2013, 11:46 PM
-
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.
June 18th, 2013, 10:30 AM
-
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.
June 19th, 2013, 07:01 AM
-
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');});
}