473,387 Members | 1,569 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,387 software developers and data experts.

Embeding javascript in php

196 100+
I know that you can echo html in a .php page, but can you echo html with a javascript aswell?

For example


Just html
Expand|Select|Wrap|Line Numbers
  1. echo '<p>' . "hello world" . '</p>';
Then with javascript

Expand|Select|Wrap|Line Numbers
  1. echo '<script type="text/javascript">
  2. document.write("Hello World!");
  3. </script>';
Any help with this or a similar method would be greatly appreciated thanks,


[EDIT]

Don't worry i answered my own question lol thanks anyway
Jul 12 '08 #1
1 1339
Right, you've answered your own question: Yes, you can!

BUT... You're really mixing up everything here. I recommend you try Smarty ( http://www.smarty.net/ ) and keep your pages separated in three files:
- page.php - contains the _php code_, initializes the smarty object and sets variables, includes page.tpl
- page.tpl - contains the html code mixed with _smarty templates_ and includes the javascripts required
- page.js - contains the _javascript code_

If you don't split things up, you'll mash everything up and it will be impossible for anyone to understand what you are doing. Using PHP to echo JavaScript code so that it would come out in the HTML page is just awful :o)
Jul 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sascha Kerschhofer | last post by:
Hi, I am embeding my SVG Files in HTML in this way: <OBJECT DATA="foo.svg" WIDTH="300" HEIGHT="200" TYPE="image/svg+xml"> (using Acrobat SVG Viewer) Since I create the SVG dynamicaly the WIDTH...
2
by: BigOne | last post by:
I'm looking for a script that embeds the text typed on a hidden(and protected) page in to a other page that can be viewed for visitors this text must stay till the owner sets a new text this is...
2
by: Raj Dhrolia | last post by:
Hi Everyone, I have some HTML snippets (with about 15 HTML controls) that needs to be embedded into my server control. I need these HTML controls on client side for some processing (JS). What...
1
by: swethak | last post by:
hi, i have a javascript variable var monthNum and i assigned some value in javascript.Now i use that variable in jsp as <% pstatement2 = connection.prepareStatement("Select * from...
1
by: tokcy | last post by:
Hi, I am embeding flash player in my site but i have some problem like... suppose i have 5 songs and i am playing one song but i want to play another while first one is not completed then both...
5
omerbutt
by: omerbutt | last post by:
hi i am trying to use javascript in the anchor tag within the href attribute but it is not picking the value instead it is posting the javascript as a text when i click that link here are the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.