473,563 Members | 2,735 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 2174
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
1807
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 second is a rule code that highlights the row you are currently moused over. Both are making use of CSS style sheet to do all of their formating. My...
0
1322
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, public DSAuthors OpenAuthors( ) public DSAuthors SaveAuthors( DSAuthors dsDelta ) 2. Web service (WSAuthors) with two methods as well:
4
2348
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 back correctly including add, change and delete to the original data. When I pull the data from the db, I store a copy in a Dataset. So I end up...
2
3235
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. objWord.Application.Visible = True ' Set the mail merge data source as the db3 database.
8
9504
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 each person for whom a mail merge letter is desired. The query reads address info from the table for each record where is true.
3
5570
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 document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm...
4
21663
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 items that don't do anything. MDI Container.IsMdiContainer = true MenuStrip.AllowMerge = true /// First menu items this.miFile.MergeAction =...
15
9030
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
8103
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...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6244
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...
1
5481
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...
0
5208
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...
0
3634
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2079
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
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.