|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am attempting to show two records at a time from a database query. I have previous and next buttons that work. However, I am wanting to include a "jump to" pull down menu as part of the functionality.
To get this to work, I am needing to pass a variable stating what page I am on through a JavaScript onChange function. If I print the variable to the page outside of the onChange function, it shows the correct page number. If I use the variable inside of the onChange function it is not coming out correctly. It is holding the value of the previous page instead of the current page. Am I missing something or is there a different way to include a variable in a JavaScript function. Your insight is appreciated. Code: <? $marker = 1; if ($offset == 0) {$marker = 1;} else {$marker = ($offset/2) + 1;} ?> <form> <? print($marker); ?> <br><br> <select name="PageJump" onChange="top.location.href='sample.phtml?page=<? print($marker); ?>&offset='+ this.options[selectedIndex].value"> <? for ($i=1;$i<=$pages;$i++){ $newoffset=$limit*($i-1); print("<option value=" . $newoffset . " >page " . $i . "</option>"); } ?> </select> </form> The first print($marker) is correct. The print($marker) located inside the JavaScript is not. Thank you for any help. |
|
#2
|
|||
|
|||
|
bramsey-
Every .selectedIndex is a property of a select object rather than a global (window.) variable; try <select name="PageJump" onChange="top.location.href='sample.phtml?page=<?print($marker); ?>&offset='+ this.options[this.selectedIndex].value"> |
|
#3
|
|||
|
|||
|
Passing PHP variable to Javascript
Thanks for the input. I figured it out earlier this morning right after I posted this. That is exactly what I did. It worked perfectly.
Thank you for your response. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Passing PHP Variable to Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|