Question is on how to work with php variables in a webpage, using javascript/jquery. The following code represents the scenario.
PHP Code Snippet for pagination –
if($current_page>1)
$previous = $current_page - 1;
else
$previous = $current_page;
if($current_page==$num_pages)
$next = $current_page;
else
$next = $current_page + 1;
//the line below is for right arrow link - go to next page
<?php echo '<a href="gallery.php?p=' .$next. '">
<img src="Arrow-Right.png" width="16" height="16" title="Next Page" /> </a>';
?>
//the line below is for left arrow link - go to previous page
<?php echo '<a href="gallery.php?p=' .$previous. '">
<img src="Arrow-Left.png" width="16" height="16" title="Previous Page" /> </a>';
?>
Now my question –
I want to disable the left and right arrow links based on the condition –
if $current_page = $num_pages (meaning, if max page has reached), then use javascript to disable the right arrow link
if $current_page = 1 (meaning, if min page has reached), then use javascript to disable the left arrow link
Pretty simple scenario for pagination, but my concern is over how to use the variables correctly, since $current_page, $num_pages etc..are all PHP variables, and I assume they cannot be accessed readily in any Javascript code. So how do i access them, so that I can use JS to further work on link enabling/disabling or css styling using js etc…
Appreciate any pointers on the above.
Javascript variable
next_pagewill be ready for use.