473,499 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused on how to merge javascript with php

36 New Member
Wutup

Im trying to write a php script that has a link. When the user clicks the link the link turns into a text field which the user can modify. When the user clicks elsewhere the text that the user typed is turned back into a link. Ive got the php script which Im supposed to change and I got a piece of javascript code that does the whole link changing of link to textfield and back again thing.

Problem Im having is I dont understand how to combine the two together. I tried to echo the javascript tags similar to how html tags can be echoed but that didnt work. I googled and found examples similar to this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo("This is php");
  4. ?>
  5.  
  6. <script....
  7. //javascript stuff goes here
  8. </script>
  9.  

Is there any way I can put the javascript within the php part of the code?

Thanks
Nov 29 '07 #1
6 2166
code green
1,726 Recognized Expert Top Contributor
Javascript calls belongs within the HTML.
Ideally close the php tags then write the HTML.
[PHP]<?php
echo("This is php");
?>
<script...etc>
//javascript stuff goes here
</script>[/PHP]
If you must place within php then echo out the HTML
[PHP]<?php
echo("This is php");
echo '<script>
//javascript stuff goes here
</script...etc>';
?>[/PHP] But I suspect this is not what you are asking
Nov 30 '07 #2
orfiyus
36 New Member
Actually I tried just echoing out the javascript. I have a bunch of javascript functions and html lines that call these functions. When I try just echoing it out I get a blank page.

I shouldve just posted the code Im working with right off the bat here it is its pretty short. Can you take a look maybe theres an error I dont see ?

Thanks

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo("<html><body>");
  4. echo("<TITLE>COMBO2.PHP</TITLE>");
  5. echo("<BR><B><U>THIS Is the test to combine php javascript and html<br></U>");
  6. echo("<BR><BR>");
  7.  
  8.  
  9. echo("<script type="text/javascript"><!--\n");
  10. echo("function editLink() { ");
  11. echo("var myLink = document.getElementById('my_link'); ");
  12. echo("var myInput = document.getElementById('my_input'); ");
  13.  
  14. echo("myInput.value = myLink.innerHTML; ");
  15. echo("myLink.style.display= 'none'; ");
  16. echo("myInput.style.display = 'inline'; ");
  17. echo("} ");
  18.  
  19. echo("function doneEdit() { ");
  20. echo("var myLink = document.getElementById('my_link'); ");
  21. echo("var myInput = document.getElementById('my_input'); ");
  22.  
  23. echo("myLink.innerHTML = myInput.value; ");
  24. echo("myLink.style.display = 'inline'; ");
  25. echo("myInput.style.display = 'none'; ");
  26. echo("} ");
  27.  
  28. echo("//--></script>");
  29.  
  30. echo( "<a id="my_link" href="javascript:editLink()">Click Me</a> ");
  31. echo( " <input type="text"  style="display: none;" ");
  32. echo( "id="my_input" ");
  33. echo( "onblur="doneEdit()"/> ");
  34. echo("<br>");
  35. echo(" </body></html>");
  36. ?>
  37.  
Nov 30 '07 #3
code green
1,726 Recognized Expert Top Contributor
Well for a start echo is not a function so you don't need brackets.
Nor in this situation do I see a need for echo, just place the code ouside the php tags.
i am a little confused with why you are using php.
Anyway, I don't see a <head> tag even though you are using <title>.
Javascript is touchy about things like that
Nov 30 '07 #4
orfiyus
36 New Member
Im trying to do it this way because Ive got a huge php script to modify in the same way and I dont know if I ll be able to seperate the it into 2 php blocks. and the <head> tag didnt do anything when I added it in.

I guess I ll try it on the huge one and see wut happens cant hurt now that I think of it.

Worst case scenario I ll have to convert these javascript functions to php functions (hopefully it ll be possible).
Nov 30 '07 #5
code green
1,726 Recognized Expert Top Contributor
I take it you are aware of Javascript being client-side and php being server-side and the implications of mixing the two?
Nov 30 '07 #6
orfiyus
36 New Member
I take it you are aware of Javascript being client-side and php being server-side and the implications of mixing the two?
yea I guess thats gonna be a problem. Wutever I ll just seperate the huge script and see if that works. If not I ll just rewrite the javascript into php.
Nov 30 '07 #7

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

Similar topics

0
1804
by: EasyRider41 | last post by:
I am trying to merge to scripting samples I for on a source code web site and having limited luck. Then first one is called Zebra Tables witch colors alternate rows of a table to look beter. The...
0
1309
by: lc | last post by:
Actually, I have things working but am not clear why do they work. Here's the setup: 3 projects 1. Data component (DataAuth) with connection, adapter and typed dataset (DSAuthors). Two methods,...
4
2343
by: John Smith | last post by:
..Net 2003 C# I get xml from a sql database pull. I put the data into a XMLDomDocument and then the user changes it. I now need to update the database correctly. I need to be able to get the data...
2
3225
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
8
9490
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
5566
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
4
21653
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of...
15
9019
by: hobosalesman | last post by:
Is there a function or library somewhere that merges 2 JSON data structures? For instance this: { "one": } plus { "one": } equals
0
7130
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
7007
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
7171
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,...
0
7220
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
7386
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...
0
5468
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,...
1
4918
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...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.