How do we insert PHP code into JavaScript code?
Published: July 5, 2009

Question:
How do we insert php code into javascript code?

Answer:
PHP is server-side code which means that the code is executed on the web server. The pages are dynamically created and sent to the user's browser.

JavaScript is a client-side code which means that it runs on the user's computer after the page has been sent from the server.

It is possible to combine PHP commands within JavaScript commands.

You would mainly use this in setting up starting variables for your JavaScript.

Example:
<script language='JavaScript'>
<!--
var BoxColor = <?php echo $color;?>;
…etc
-->
</script>

Another option is that you may consider using Ajax which allows you to dynamically call server-side code from JavaScript.

About the Author
Rich Agnew is an author for The Computer Geek Custom Web Page Design. The Computer Geek is a web design company that prides itself in professional service at a fraction of the cost. The Computer Geek specializes in Custom Web Design, PHP & MySql and Ecommerce.

Customer Reviews:

Published: January 14, 2017
Searching for a competent English-speaking webmaster can be a daunting task, especially if searching the Internet without a personal recommendation from a friend. I discovered Computer Geek's website, liked what I read, and contacted Rich. He promptl...[Read More]
Rand Winburn
randw@iconbusters.com

 

Published: December 22, 2016
Excellent communication and quick to get the job done....[Read More]
Adam Roberts
adamrobertswork@gmail.com

 

Published: July 27, 2016
BEST SERVICE I HAVE EVER EXPERIENCED !!! Called Rich one morning to have my website fixed since it was hacked . I must say he really knows what he is doing in no time at all my site was back on line all malware removed and my web site updated and pro...[Read More]
Eric Bjorkgren
preservewax@gmail.com

 

Published: July 27, 2016
Rich and Justin really know their stuff. Whenever an unexpected issue comes up, which happens a lot in our business, they fix the issue immediately while providing exceptional customer service. I truly enjoy working with them and I recommend them to ...[Read More]
Yoni Lautman
ylautman@samaplastics.com

 

Published: June 25, 2016
"I was notified by my web hosting service that they had deactivated my website due to the presence of malware. I contacted Rich, described my issue (via online chat.. Made it very easy), and within the first 30 minutes, I received a quote, and within...[Read More]
Kevin Costello
kcostellocpa@gmail.com

 

Published: June 13, 2016
Rich saved my life!!! I was hacked and Rich saved me. It was a terrible experience, as is always the case when you deal with some pointless, yet malevolent malware created by some greasy faced kid living in his grandmothers basement. My host i...[Read More]
Adam Sommer
kosmognosis@gmail.com

 

Published: April 19, 2016
On Saturday I discovered one of my 6 websites had been hacked and links were leading to porn sites. I was devastated. I found Computer-geek.net online, and filled in a form. This was a weekend, and almost immediately Evan contacted me. His knowledge ...[Read More]
Diana Walker
diana@dianawalker.com

 

Published: March 8, 2016
I had website builder working on my new site for 3 weeks, at the end of 3 weeks I didn't have a completed website. I contacted the computer geek, within a week of working with me, I now have a website. The service was excellent and very professional....[Read More]
Timothy Holt
trholt44@gmail.com

 

Published: February 21, 2016
"I found myself stuck with an email response form issue on a clients website. These guys spoke to me over the phone and quoted me a price. Happily, they stayed within the initial quote and fixed my problem. If I ever need help again they will be the ...[Read More]
Robert Jordon
papajordan53@gmail.com

 

Published: February 18, 2016
"I had a great experience with help from Computer Geeks. I was above my pay grade with a PHP update and spent 2 days of wasted time trying to fix the issue but without the knowledge to do it. Matthew was great, solved the problem on the first go and ...[Read More]
Joel Posluns
nsaiki@telus.net

 

[Read More Testimonials Here]

Latest Website Related Articles

Google is Now Starting to Enforce SSL / HTTPS Starting January 2017

Published: January 21, 2017
Google has announced starting January 2017, Google Chrome will be looking at all websites with any type of web form or login area. If those form pages are not protected with a valid SSL Certificate using HTTPS, a NOT Secure warning will show up...[Read More]

 

How to fix your hacked wordpress website - simple version

Published: January 9, 2017
This is a quick tutorial on how to fix your WordPress website when you have been hacked. This version assumes that you can access the WordPress admin. First of all on the site I was repairing, my anti virus desktop software gave me a w...[Read More]

 


Here are some links to related topics:
 hiring a webmaster,   php webmaster,   oscommerce consultant,   hire oscommerce developer,  


Site Secured By The Website Guardian
How do we insert PHP code into JavaScript code? | Computer Geek 5 out of 5 based on 103 user ratings.
How do we insert PHP code into JavaScript code? | Computer Geek
How do we insert PHP code into JavaScript code? - Question:How do we insert php code into javascript code? Answer:PHP is server-side code which means that . . .
How do we insert PHP code into JavaScript code? | Computer Geek
Date Published: 10/09/2016
How do we insert PHP code into JavaScript code? - Question:How do we insert php code into javascript code? Answer:PHP is server-side code which means that . . .
5 / 5 stars