943,619 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 5126
  • PHP RSS
Jun 20th, 2006
0

merge javascript with php...

Expand Post »
can javascript merge with php?...if so,how can we implement it...
i had a hard time searching on that problem....
i made experiments but it doesn't work...hehe
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ayajhane_dhagz is offline Offline
7 posts
since May 2006
Jun 29th, 2006
0

Re: merge javascript with php...

You can use PHP to generate JavaScript in a client side script, but if you are talking about getting PHP (a server side language) to talk to JavaScript as a client-side language, you cannot do it.

PHP is executed on the server. JavaScript in a Web page is executed in the user's browser.
Last edited by TopDogger; Jun 29th, 2006 at 11:04 am.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Jun 29th, 2006
0

Re: merge javascript with php...

Actually, you can code functions in javascript that talk to php. You send data and get a response. AJAX.

This whole forum uses that ability. But, as pointed out, the javascript runs on your browser, and the php on the webserver. But the two talk.
Last edited by noppid; Jun 29th, 2006 at 5:36 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noppid is offline Offline
17 posts
since Jan 2004
Jun 30th, 2006
0

Re: merge javascript with php...

<"You can use PHP to generate JavaScript in a client side script">
how can i do that?..^__^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ayajhane_dhagz is offline Offline
7 posts
since May 2006
Jun 30th, 2006
0

Re: merge javascript with php...

I sometimes find that I need to use PHP to generate a JavaScript array that is used by an application. In this situation, I am probably using data in a MySQL database to generate the array. This is no different than when you generate any other client-side code.

For example, if you had a MySQL table loaded with names of books that you want to use to generate a JavaScript array, you would do something like this:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. echo "var bNames = new Array(";
  3.  
  4. $sql = "SELECT book_name FROM books ORDER by book_name";
  5.  
  6. $rs = mysql_query($sql);
  7.  
  8. while($row = mysql_fetch_array($rs))
  9. {
  10. echo "\"".$row['book_name']."\",";
  11. }
  12. echo "\"\"";
  13. echo ");\n";
  14. ?>
This generates the following client-side JavaScript array:

PHP Syntax (Toggle Plain Text)
  1. var bNames = new Array("book name 1","book name 2","book name 3","");
Before you jump into using JavaScript heavily for Web applications, keep in mind that JavaScript should never be used for a critical function. According to the W3Schools surveys, up to 10% of users have JavaScript disabled in their browsers. I think this is mostly due to people who set the security level to high in Internet Explorer, which disables all active scripting, including JavaScript.
Last edited by TopDogger; Jun 30th, 2006 at 11:26 am.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Jun 30th, 2006
0

Re: merge javascript with php...

Quote originally posted by ayajhane_dhagz ...
<"You can use PHP to generate JavaScript in a client side script">
how can i do that?..^__^
You echo out the javascript like any html. The example above while not complete, explains echo.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noppid is offline Offline
17 posts
since Jan 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Mambo Administrator Problems - Page Not Found
Next Thread in PHP Forum Timeline: php + Javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC