{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 software do I need to write PHP? being.chinmay 5 222 11-05-2017, 11:12 PM
Last Post: davidsmith21
  What is called as negative infinity in JavaScript? sulbha 9 105 10-16-2017, 10:54 PM
Last Post: touchstone
  What are all the types of Pop up boxes available in JavaScript? sulbha 1 13 10-05-2017, 07:45 PM
Last Post: Martinricky
  How to run a Bash script via PHP and match the output? Martinricky 0 13 09-26-2017, 07:03 PM
Last Post: Martinricky
  How Does PHP Updates by Your Web Host Impact your WordPress Sites Garrysmith 1 32 05-07-2017, 11:40 PM
Last Post: tonnygrand
  How to get difference between two or more arrays in PHP? tonnygrand 1 27 04-19-2017, 07:41 PM
Last Post: Davidwatson
  What is PHP Frameworks ? parisahu13 10 75 03-16-2017, 12:56 AM
Last Post: RGBpro
  How to submit PHP contact form to an email tonnygrand 2 40 02-16-2017, 12:21 AM
Last Post: raynowenhall
  How to Open Popup using javascript tonnygrand 2 82 01-17-2017, 01:33 AM
Last Post: ITSGOLIVE
  Live Chat API SDK for PHP Websites hudsonlane 1 263 10-24-2016, 06:57 AM
Last Post: Aryansao

Forum Jump:


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