473,729 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embeding javascript in php

196 New Member
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 1355
rohypnol
54 New Member
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
3183
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 and HEIGHT is unknown, when loading the HTML page. Can I embed SVG like I can do it with images without defining WIDTH and HEIGHT. Simply "oversize" both attributes unnecessarily produces scrollbars in the browser window.
2
1299
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 to update a site of a restaurant and they want to chance just the "menu of the day" (one textline only) thanks in advance The BigOne
2
1094
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 is the best way to implement this? One most straight forward way i can think of is to have something like - Response.Write("<long HTML string>");
1
1692
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 importtimetable where month='"+monthNum+"'"); %> In that where condition monthNum is jascript variable. I used like that i got a error.
1
1232
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 songs are playing that do not i want ... i want like at time only one shog should play. Is there any scripting to do this? I am giving the code which i have embed
5
2006
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 combination i have already tried. <a href="index.php?nxId=document.getElementById('questions').options.value"></a> <a href="index.php?nxId=<script type='text/javascript'>document.getElementById('questions').options.value</script>"></a> <a...
0
8913
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.