473,388 Members | 1,468 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,388 software developers and data experts.

Converting JavaScript variable to php

190 100+
is there any method by which i can convert javascript variables to php variables
Jun 14 '08 #1
17 12478
rizwan6feb
108 100+
Most of the begginers try to do this?
It doesn't make any sense assigning javascript variables to PHP variables. You can pass the values of javascript variables to a PHP script, where you can get those values into PHP variables. There are different ways of passing values from client (browser) to PHP script
Jun 14 '08 #2
Markus
6,050 Expert 4TB
Could you explain in what situation you would need to do this?

Thanks.
Jun 14 '08 #3
Atli
5,058 Expert 4TB
is there any method by which i can convert javascript variables to php variables
Javascript can not interact with PHP directly.
This is due to the fact that Javascript is run on the client's browser (client-side) while PHP is executed on the server (server-side).
So, before your Javascript code is even read by the browser, all of the PHP code will already have been executed by the server.

There are two ways to have Javascript communicate with PHP.
Either you have to refresh/redirect the page, sending along the data via the POST or GET protocols.
Or, you can use AJAX.

I would still be very careful when using data sent by Javascript. As it is generated by the client's browser, it can easily be manipulated before it is sent.
Make sure you validate it before you use it.
Jun 14 '08 #4
Not,
u can use php variable in javscript but cant use javascript variable in PHP because php can not parrsing the javascript value....

Regards,
Sandeep agarwal
Jun 20 '08 #5
r035198x
13,262 8TB
..u can use php variable in javscript ...
How ?
Jun 20 '08 #6
Atli
5,058 Expert 4TB
How ?
I'm guessing hes talking about just echoing PHP values into the Javascript code?

For the record, using that method, the Javascript code is in fact not using a PHP variable. The PHP code is used to create a Javascript variable, which Javascript can then use.
Jun 20 '08 #7
pbmods
5,821 Expert 4TB
"Converting" a variable from JavaScript to PHP or vice versa is kind of like trying to "convert" a 20-Euro note into a butternut squash. You have to go through the grocer, or else you're bound to get some funny looks.

And for 20 Euros, it better be one heckuva butternut squash. I'd say this is about the point where the analogy breaks down.

Anyway, PHP is executed on the server side, whereas JavaScript works on the client side, and the two *never talk to each other*.

In fact, PHP technically doesn't even know that the User's computer even exists; the HTTP server handles all those details.

PHP can output JavaScript code that (once the User's browser executes that code) will create a JavaScript variable with a particular value.

You can also pass parameters in an HTTP request that PHP converts into elements in the $_GET superglobal.

But the "conversion" process has to be done in a roundabout way because, as noted before, PHP and JavaScript don't talk to each other, and in fact, they are not even aware of each other's existence.
Jun 22 '08 #8
Atli
5,058 Expert 4TB
"Converting" a variable from JavaScript to PHP or vice versa is kind of like trying to "convert" a 20-Euro note into a butternut squash. You have to go through the grocer, or else you're bound to get some funny looks.
Brilliant analogy :)
Although I am not really sure what a butternut squash is.
Jun 22 '08 #9
pbmods
5,821 Expert 4TB
Brilliant analogy :)
Although I am not really sure what a butternut squash is.



Squtterbut Nash!
Jun 22 '08 #10
Atli
5,058 Expert 4TB
wow.. that thing looks dangerous :P
Jun 23 '08 #11
coolsti
310 100+
Actually, it is quite tasty! The meat is like pumpkin, just a bit more compact. Great for stews and it gives a bit of a flare to stir fry.
Jun 23 '08 #12
zorgi
431 Expert 256MB
Actually, it is quite tasty! The meat is like pumpkin, just a bit more compact. Great for stews and it gives a bit of a flare to stir fry.
I don't like pumpkin
Jun 23 '08 #13
r035198x
13,262 8TB
Actually, it is quite tasty! ....
Agreed .
Jun 23 '08 #14
Markus
6,050 Expert 4TB
From javascript variables in PHP, to Butternut Squash.

Just another day on Bytes.com
Jun 23 '08 #15
r035198x
13,262 8TB
I don't like pumpkin
That's a shame. It's one of the staples in the rurals areas (where I grew up). Gives a lots of energy was easy (read cheap) to get since we grew them in our maize fields.
Jun 23 '08 #16
coolsti
310 100+
Poor OP, here we are talking about mini-pumpkins instead of Javascript and PHP.

But those who "don't like pumpkin" should try this squash. It is quite good in Thai, Phillippine and Chinese recipes. It has a more refined taste than pumpkin and holds its form better when cooked.
Jun 23 '08 #17
r035198x
13,262 8TB
...But those who "don't like pumpkin" should try this squash. It is quite good in Thai, Phillippine and Chinese recipes. It has a more refined taste than pumpkin and holds its form better when cooked.
Tastes even better in margarine.
Jun 23 '08 #18

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

Similar topics

7
by: Nige | last post by:
Is it possible to convert an item of form field data to uppercase using the toUpperCase() method? What I'm really asking is, how do I reference the data item? -- Nige Please replace YYYY...
10
by: jose.jeria | last post by:
I use the following to convert uppercase to lowercase: translate($queryString, 'ABCDE...', 'abcde...') But how can i convert the case for umlauts? φεδ etc
3
by: barry | last post by:
I have the following: function(NAMED) { sString.Append("document.forms.NAMED.style.visibility = 'hidden'") } and would like to convert the NAMED into the object it represents - for example in...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
7
by: kmitchell00 | last post by:
I am coding in Coldfusion MX7 and using Javascript for some of the functionality. The basic functionality I'm coding is, based on a value the user chooses from a dropdown box, I populate address...
10
by: kumuda v | last post by:
Hi all, How to convert a php variable into the javascript variable. I need this because i want to display the content of php variable in the textbox of html field. With regards
4
by: sumanbangladesh | last post by:
hi I am new both in php and javascript. I have a javascript varialbe. But I need a php variable with the same contents.How can I do it. thanks in advance
6
by: gubbachchi | last post by:
Hi, How to convert a javascript variable to php variable. Could anybody help me to do this.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.