merge javascript with php...

Reply

Join Date: May 2006
Posts: 7
Reputation: ayajhane_dhagz is an unknown quantity at this point 
Solved Threads: 0
ayajhane_dhagz's Avatar
ayajhane_dhagz ayajhane_dhagz is offline Offline
Newbie Poster

merge javascript with php...

 
0
  #1
Jun 20th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: merge javascript with php...

 
0
  #2
Jun 29th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 17
Reputation: noppid is an unknown quantity at this point 
Solved Threads: 0
noppid noppid is offline Offline
Newbie Poster

Re: merge javascript with php...

 
0
  #3
Jun 29th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 7
Reputation: ayajhane_dhagz is an unknown quantity at this point 
Solved Threads: 0
ayajhane_dhagz's Avatar
ayajhane_dhagz ayajhane_dhagz is offline Offline
Newbie Poster

Re: merge javascript with php...

 
0
  #4
Jun 30th, 2006
<"You can use PHP to generate JavaScript in a client side script">
how can i do that?..^__^
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: merge javascript with php...

 
0
  #5
Jun 30th, 2006
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:

  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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 17
Reputation: noppid is an unknown quantity at this point 
Solved Threads: 0
noppid noppid is offline Offline
Newbie Poster

Re: merge javascript with php...

 
0
  #6
Jun 30th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC