{myadvertisements[zone_1]}
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using PHP variables with JavaScript
#1
You can use PHP variables with JavaScript the same way you do with HTML.You can add the variable to the JavaScript code. For example, the JavaScript example in the preceding section can include a PHP variable, as follows:

Quote:<?php
$string = “This page last updated: “;
echo “<script language=\”JavaScript\”>
<!--
document.write(‘$string’
+ document.lastModified + ‘<br>’)
// -->
</script>”;
?>

The JavaScript language itself uses variables. You can set a JavaScript variable to the value of a PHP variable to use in your JavaScript code. For example, the JavaScript could be sent as follows .


Quote:<?php
$string = “This page last updated: “;
echo “<script language=\”JavaScript\”>
<!--
var message = \”$string\”;
document.write( message
+ document.lastModified + ‘<br>’)
// -->
</script>”;
?>

Because JavaScript code is not executed until it reaches the browser on the client side, passing values from JavaScript variables to PHP variables can’t take place in the current page. The JavaScript value must be passed on to the next PHP script before PHP can receive it. JavaScript can pass the values on so that PHP can use them by adding them to the URL, by storing them in a cookie that PHP can read, or by sending them as a form element.
Reply
{myadvertisements[zone_3]}


Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the difference between require() and include() in PHP? Davidwatson 2 11 04-19-2018, 08:50 PM
Last Post: successmantra3
  How to send an SMS using PHP script Garrysmith 5 47 03-30-2018, 09:39 PM
Last Post: successmantra3
  What is the best way to learn php frameworks? indusri 6 67 03-18-2018, 07:41 PM
Last Post: alberto-m
  Why Custom PHP Web Development Is Always A Hot Option For Business Development? redlogics 5 740 03-04-2018, 09:18 PM
Last Post: nehaxavier
  What software do I need to write PHP? being.chinmay 10 257 12-27-2017, 07:38 PM
Last Post: Keerti
  What is called as negative infinity in JavaScript? sulbha 9 124 10-16-2017, 10:54 PM
Last Post: touchstone
  What are all the types of Pop up boxes available in JavaScript? sulbha 1 16 10-05-2017, 07:45 PM
Last Post: Martinricky
  How to run a Bash script via PHP and match the output? Martinricky 0 20 09-26-2017, 07:03 PM
Last Post: Martinricky
  How Does PHP Updates by Your Web Host Impact your WordPress Sites Garrysmith 1 44 05-07-2017, 11:40 PM
Last Post: tonnygrand
  How to get difference between two or more arrays in PHP? tonnygrand 1 36 04-19-2017, 07:41 PM
Last Post: Davidwatson

Forum Jump:


Users browsing this thread: 1 Guest(s)
{myadvertisements[zone_2]}