JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 5th, 2001, 08:31 AM
bramsey bramsey is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: USA
Posts: 226 bramsey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 35 sec
Reputation Power: 8
Question Passing PHP Variable to Javascript

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.

Reply With Quote
  #2  
Old September 5th, 2001, 02:49 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
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">

Reply With Quote
  #3  
Old September 5th, 2001, 02:55 PM
bramsey bramsey is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: USA
Posts: 226 bramsey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 35 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Passing PHP Variable to Javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway