473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Use Javascript variable in PHP

I am a beginner in programming. I just want to know how can i use a variable used in javascript in my php coding.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo '<script language="JavaScript">
  3. var ace= prompt("Enter your name please", "Name");
  4. </script>';
  5. ?>
  6.  
  7. <html>
  8. simple html coding..
  9. <?php function_name(ace in script);?>
  10. </html>
  11.  
  12. <?php
  13. function_name($ace)
  14. {
  15. echo'your name is'.$ace.'!';
  16. }
  17. ?>
Oct 6 '10 #1
2 1307
Frinavale
9,735 Expert Mod 8TB
PHP runs on the web server where as JavaScript runs in the browser. Since they run in completely different environments on completely different computers, these two technologies cannot share variables...

However, both can access HTML elements...like HiddenFields or Cookies.

So, in your PHP code, set the value of a HiddenField element so that when your JavaScript runs it can retrieve the value from the HiddenField....You can also set the value of the HiddenField using JavaScript so that you can retrieve it in your PHP code.

-Frinny
Oct 6 '10 #2
Markus
6,050 Expert 4TB
Just use JavaScript. Simples.
Oct 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matt | last post by:
If I assign Java variable a to javascript variable x, it is fine. <% int a = 10; %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error. any ideas??
5
by: ms_chika | last post by:
Hi to all, I have this problem in xsl wherein i want to access a variable in javascript and use it my xsl. How would i access or use a javscript variable in my xsl file? Please help. ...
4
by: tnhoe | last post by:
Hi, if I have both javascript and aspscript, how to get/retrieve the variable value in javascript into asp variable ? regards hoe
3
by: mbasil7 | last post by:
Hi at all! I want to use a javascript variable in php. The reason is that i want to know the client's screen resolution. Keep in mind that i am not a javascript programmer but php. Here is...
3
by: stahl.karl | last post by:
I have a CGI/Perl program that returns a string output. Is it possible to get this into a Javascript variable, where the name of the variable is defined in the Javascript and not in the Perl code?...
6
by: leppert | last post by:
Hello, I am trying to access a javascript variable on another site. The site requires the user to be logged in, so what I am doing is submitting a form and redirecting the output to an IFRAME,...
2
by: pleaseexplaintome | last post by:
Hi I have the following perl/cgi script snippet. The goal of this script is to pass a javascript variable to perl where it can be re-used later. Any help is appreciated, Thanks ...
5
by: nbt725 | last post by:
Dear Sir, Hello ! I want to get the javascript variable in php code in following function. <script language="JavaScript"> function chg_subcatg(cfield,fieldnm) { // For Retrieval of current...
3
by: sasimca007 | last post by:
Hello friends, IN modperl we write perl with html,javascript and etc. when we are writing perl code in the middle of javascript and if we want to assign a javascript variable...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.