answersLogoWhite

0

JavaScript lives in the browser, PHP lives on the server.

To pass a value from JavaScript to a PHP page, you can either

  • do an HTML form submit
  • use AJAX

In both cases, the value is sent to the server and you write your PHP to handle it and send a response.

The important thing is that the JavaScript value won't be available in PHP when you first generate the page, creating the page and handling the value submitted from the browser are two distinct steps.
User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

How do you call JavaScript object in PHP?

You cannot do that, since PHP is serverside and javascript is clientside. The best way is usually to have an ajax layer (a php file) to handle requests from the main php file. For example: You would have 3 files index.php, ajax.php, and functions.js The index.php is what people would see, and would include the functions.js javascript file. The functions.js file would then send requests to ajax.php. These requests could be a search query, a login request, etc... or any other object for that matter. Accessing javascript objects on demand is not possible though.


How do you pass table values from one page to another using HTML?

You cant you have to use php or javascript.


Why we use javascript as we have a powerful scripting language php?

First of all, PHP is server side, Javascript is client side. You cannot detect mouse gestures or any clicks with PHP the same way you cannot read a file or modify it or process a form (unless you use AJAX of course). Also, although I love PHP, and it has useful extensions such as the GD library, PHP is not a very good language. Overall we use javascript and PHP because they are used for two completely different things.


How do you do the pass the variable value to the query in same php page?

To pass PHP Variable value in Jquery simpley echo that variable : Eg <script> var jQueryVariable=<?php echo $anyVariable?> </script>


When should globals be used in PHP?

Problem with using global variables in php is that they lose the the assigned value in a different php file. They only keep the global variable value in the php file in which they are declared. Instead of globals try and use $_SESSION or $_COOKIE to keep value intact across different php files in a project


How can you declare the variable in PHP?

Variables in PHP do not need to be declared like some languages (e.g. JavaScript). This is all that needs to be done to assign a variable: $variable = "Value";


Is php a binary file?

No, PHP is text file with .php extension.


What are the similarities between PHP and JavaScript?

there are not many similarities, except the if and else statements, loops, etc... but PHP talks to the server, JavaScript can't. That's why both languages have totally different functions. If you only use basic JavaScript, PHP doesn't differ too much.


Does JavaScript interact with PHP?

Yes, JavaScript and PHP can interact with each other in web development. JavaScript is a client-side scripting language that runs in a user's browser, while PHP is a server-side language that runs on the server. The two languages can communicate with each other through the use of AJAX (Asynchronous JavaScript and XML) requests. JavaScript can make an AJAX request to a PHP script on the server, and the PHP script can process the request and return data back to the JavaScript code. This allows for dynamic, interactive web pages that can update their content without requiring a full page refresh. Overall, JavaScript and PHP are complementary technologies that can work together to create powerful web applications


How do you create a text editor in PHP?

Well it got nothing to do with PHP, you going to need JavaScript to do that :)


Can you open php file in your PC?

Since a PHP file basically is a text file, yes. But beware - opening and running a PHP file are not the same. If you want to run a PHP file, you will need a webserver with PHP module enabled.


What file extension is used to save a php file after code has been written into it?

The file extension for PHP is .php