Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Using php variables in javascript?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Using php variables in javascript?

Postby flash_harry » Wed Apr 02, 2003 6:54 am

I have a javascript menu which I want to post links onto automatically. Is there anyway to pass php variables into javascript. If so, how do you do it and an example using this code i have produced

<script language="JavaScript">
function mmLoadMenus() {
if (window.menu_1) return;
window.menu_1 = new Menu("root",141,20,"Haettenschweiler",20,"#000000","#cccccc","#cccccc","#000000","center","bottom",3,0,500,-5,7,true,true,true,0,true,true);
menu_1.addMenuItem(

I would want to put the php variables in here

"One","window.open('one.htm', '_self');");
menu_1.hideOnMouseOut=true;
menu_1.menuBorder=1;
menu_1.menuLiteBgColor='#ffffff';
menu_1.menuBorderBgColor='#cccccc';
menu_1.bgColor='#aaaaaa';

menu_1.writeMenus();
}
</script>
flash_harry
New php-forum User
New php-forum User
 
Posts: 26
Joined: Thu Jan 16, 2003 6:05 am

Postby Redcircle » Wed Apr 02, 2003 5:46 pm

you can create a hidden form and issue values from php to the hidden fields.
Code: Select all
<form method="post" action"">
<input type="hidden" name="hiddenfield" value="<?php echo $var;?>">
</form>

<script language="JavaScript">
<!--
document.write(form.hiddenfield.value);
-->
</script>
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby flash_harry » Thu Apr 03, 2003 12:53 am

OK that works, but the javascript i want to change is in the head of the page before the form would be in. Any ideas?
flash_harry
New php-forum User
New php-forum User
 
Posts: 26
Joined: Thu Jan 16, 2003 6:05 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.