473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Java Script and PHP

I have an application that uses Google Maps. This works fine but I ned
to read a file. I can do this in PHP but how to mix PHP with Java
Script? Do they live together or do I need to end each block of script
then start the php - then end it etc.

regards
Hardy
Dec 22 '07 #1
4 1347
PHP is server side and is converted to HTML by the time it reaches the
client (browser). JavaScript is client side and is interpreted by the
client (browser) on the other side.

Thus, you can write javascript with PHP but you cant write PHP with
javascript.

e.g.

<?php

echo '<script type="text/javascript">alert("javascript alert")</
script>';
?>
Dec 22 '07 #2
macca wrote:
PHP is server side and is converted to HTML by the time it reaches the
client (browser). JavaScript is client side and is interpreted by the
client (browser) on the other side.

Thus, you can write javascript with PHP but you cant write PHP with
javascript.

e.g.

<?php

echo '<script type="text/javascript">alert("javascript alert")</
script>';
?>
Or save a file named myscript.js.php. In the file you can use both
javascript and php. For example, you can write:

alert( <?php 12 + 15 ?)

and then include it in your html with:

<script type="text/javascript" language="JavaScript"
src="myscript.js.php"></script>

--
www.panoye.com :: virtual tour
Dec 23 '07 #3
Or save a file named myscript.js.php. In the file you can use both
javascript and php. For example, you can write:

alert( <?php 12 + 15 ?)

and then include it in your html with:

<script type="text/javascript" language="JavaScript"
src="myscript.js.php"></script>

--
www.panoye.com :: virtual tour
This will be send with the wrong Header (normally text/html). You have
to add
header('Content-type: application/x-javascript');
Dec 23 '07 #4
On Dec 23, 1:43 pm, Jonas Werres <jo...@example.orgwrote:
Or save a file named myscript.js.php. In the file you can use both
javascript and php. For example, you can write:
alert( <?php 12 + 15 ?)
and then include it in your html with:
<script type="text/javascript" language="JavaScript"
src="myscript.js.php"></script>

Its still the same thing. The PHP is interpreted on the server before
the javascript on the client,

so, what is sent to the client is actually

alert(27)

it's the same as having a file called script.php and writing

<script language="javascript" type="text/javascript">
alert(<?php echo 12 + 15; ?>)
</script>

Dec 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andy R. | last post by:
Hello everyone, I've spent quite some time now, looking for some information on how to get this done, sadly none has helped me much, though. I have a bit of java scrpt on a webpage (.php) to...
4
by: lawrence | last post by:
I want to offer my friends a ping service, where certain of their pages will be called once a week. My impression is that no PHP script can be made to run very long. Assuming a situation where I...
4
by: Laura P | last post by:
Hi, I wasn't sure whether this should be posted in the Java are or in a Solaris thread, so I shall post it in both. Sorry for the duplication. I am new to Solaris and am having trouble...
2
by: enclume42 | last post by:
Hello, I am a pure Linux guy. I wrote a Java program that is going to be used by some Windows people, and I wish the startup of the program to be as simple as possible, namely to double-click on...
0
by: Mircea Pleteriu | last post by:
Hi all, I have created a .NET Windows control with c#. I have placed the control on a HTML page within the OBJECT element. Everything works fine up to now. Now, I wanna implement the...
4
by: Don Grover | last post by:
I hope some one can help, I have a html table that is created with asp that has a row of repeated buttons down the side. these call a page passing a query string with invoice number. I need to...
4
by: Jeff | last post by:
Hi, Are there anyone can help me? My questions are as following: Because I have a tools bar which coding with javascript, it will reuse very often. So I want to separate the client-side java...
9
by: Mickey Segal | last post by:
The long-simmering Eolas patent dispute: http://www.microsoft.com/presspass/press/2003/oct03/10-06EOLASPR.mspx has led to an optional Microsoft Update: http://support.microsoft.com/kb/912945/en-us...
4
by: Quill_Patricia | last post by:
I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages...
0
by: tosreejithp | last post by:
Hi, My first problem was i am not able to compiled a file from java script to java class.Now its clear and working fine..now i can convert a java script file to java class by Rhino Java Script...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.