php and javascript
Moderator: General Moderators
php and javascript
I am trying to make a javasript dropdown menu with php variables. I have no clue how to pass variables to this menu from an text database file via php. I have a external js file.
The links will look like this:
link1 --> example.com/index.php?link_id=1
link2 --> example.com/index.php?link_id=2
etc. until link ids are available in the database file
Any help would be appreciated.
The links will look like this:
link1 --> example.com/index.php?link_id=1
link2 --> example.com/index.php?link_id=2
etc. until link ids are available in the database file
Any help would be appreciated.
assuming you're getting the links from a db I am?
echo out the results you should:
ex:
echo out the results you should:
ex:
Code: Select all
$result = mysql_query("select * from....");
while($row = mysql_fetch_assoc($result))
{
echo $row['link'];
}No, my problem is I don't know how to pass php variables into the js file.
here is the some line of the menu script file:
Instead of "SubMenuText 1..." I want the php generated variables. It is more difficult to me cause the numbers of submenu is always changing depending on how many links are in the db file.
here is the some line of the menu script file:
Code: Select all
startMainMenu("",0,0,2,0,0)
mainMenuItem("elements_page1_hnavbar_b1",".png",27,144,"javascript:;","","home",2,2,"elements_page1_hnavbar_plain");
mainMenuItem("elements_page1_hnavbar_b2",".png",27,144,"javascript:;","","about us",2,2,"elements_page1_hnavbar_plain");
mainMenuItem("elements_page1_hnavbar_b3",".png",27,144,"javascript:;","","services",2,2,"elements_page1_hnavbar_plain");
mainMenuItem("elements_page1_hnavbar_b4",".png",27,144,"javascript:;","","news / special offers",2,2,"elements_page1_hnavbar_plain");
endMainMenu("",0,0);
startSubmenu("elements_page1_hnavbar_b3","elements_page1_hnavbar_menu",144);
submenuItem("SubMenuText 1","javascript:;","","elements_page1_hnavbar_plain");
submenuItem("SubMenuText 2","javascript:;","","elements_page1_hnavbar_plain");
submenuItem("SubMenuText 3","javascript:;","","elements_page1_hnavbar_plain");
endSubmenu("elements_page1_hnavbar_b3");Code: Select all
startSubmenu("elements_page1_hnavbar_b3","elements_page1_hnavbar_menu",144);
<?
while($row = ...)
{
?>
submenuItem("<?=$row['linktext'];?>","javascript:;","","elements_page1_hnavbar_plain");
<?
}
?>
endSubmenu("elements_page1_hnavbar_b3");Sorry I don't get you. I quoted from js file not from php. It is an external js file that page calls.Burrito wrote:Code: Select all
startSubmenu("elements_page1_hnavbar_b3","elements_page1_hnavbar_menu",144); <? while($row = ...) { ?> submenuItem("<?=$row['linktext'];?>","javascript:;","","elements_page1_hnavbar_plain"); <? } ?> endSubmenu("elements_page1_hnavbar_b3");
have to use a php file you probably will.
use header() you should to send the file as text/javascript you must.
point to the .php file in your js src attribute you will.
ex:
use header() you should to send the file as text/javascript you must.
point to the .php file in your js src attribute you will.
ex:
Code: Select all
<script src="somefile.php"></script>Umm, I am not a php or js guru...
Above is my php code that generates links and i would like to use it with that js code i have quoted. So I want the $ma[1] variable instead of SubMenuText 1-2-3... and so on.
Code: Select all
$file=file($services_db);
$s=sizeof($file);
for($i=0;$i<$s;$i++){
$ma=explode("|",$file[$i]);
$menuitems.=' - <a href ="index.php?mode=services&serviceID='.$ma[0].'">'.$ma[1].'</a><br>';
}Thank you Burrito, I am gonna check it out.Burrito wrote:a good resource for you I have found:
http://www.javascriptkit.com/javatutors ... lphp.shtml