...

View Full Version : PHP code in javascript



levani
03-19-2009, 08:19 PM
Hi

I have a popup script written in javascript and I want to add some php code there.

This is the beginning of the code:


var defaultMenuWidth="150px" //set default menu width.

var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<a href="http://dynamicdrive.com">Dynamic Drive</a>'
linkset[0]+='<hr>' //Optional Separator
linkset[0]+='<a href="http://www.javascriptkit.com">JavaScript Kit</a>'
linkset[0]+='<a href="http://www.codingforums.com">Coding Forums</a>'
linkset[0]+='<a href="http://www.cssdrive.com">CSS Drive</a>'
linkset[0]+='<a href="http://freewarejava.com">Freewarejava</a>'

linkset[1]='<?php echo "Something"; ?>'
linkset[1]+='<a href="http://cnn.com">CNN</a>'
linkset[1]+='<a href="http://news.bbc.co.uk">BBC News</a>'
linkset[1]+='<a href="http://www.washingtonpost.com">Washington Post</a>'


How can I modify this script to make the php work properly?

See this link for whole code and more info:
http://www.dynamicdrive.com/dynamicindex1/popit.htm


Thanks in advance

Eldarrion
03-19-2009, 08:30 PM
Exactly what is not working with it? Is the file's extension 'php'? Is the server you're running it on enabled to use PHP to begin with or are you testing it locally without a server running?

ohgod
03-19-2009, 08:31 PM
where is YOUR code? what's not working?

that should work fine if it's a php page and that echo gets processed as the page is being built.

levani
03-19-2009, 08:47 PM
Well, the extension was .js and I changed it to php. Now everything seems to work fine :)

Will all php code work properly as in standard php file?

Eldarrion
03-19-2009, 08:49 PM
Don't see why it shouldn't. <?php ?> inside <script> tags is interpreted fine provided the server knows to look for it and supports it.

levani
03-19-2009, 08:54 PM
OK, thank you very very much.

Great forum!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum