+ 6
How do you save a javascript variable in a php variable?
I have a JavaScript variable with a string stored into it and I want to pass that value to a PHP website so I can send that variable to my email, how could I do that? thanks!
13 Réponses
+ 7
you should use AJAX
+ 2
Send it as a request to the server and Prozess it from there on
+ 2
javascript doesnt communicate with php directly, but they are linked via the DOM. so the solution is to store the js variable in a hidden form in html, then use php to get the info from the html.
here is a sof link which could help
https://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php
+ 1
+ 1
Salif Mehmed i think if we go into that he's more confused than before.
+ 1
I used it in here https://code.sololearn.com/w79797cF2wpP/?ref=app
+ 1
Monical and what's about ajax
0
Feichtinger Andreas could you please elaborate with code so I can add it and try it out? how should I request the variable?
0
You need to use a form to send the variable to the php script on the server.
https://www.sololearn.com/learn/HTML/1035/
0
Dhivya pls read the answeres before you post something that's already there and therefor just spam
0
Feichtinger Andreas I have add that code into the php file but can you clarify $variablename I should put the JavaScript value?
0
Mike if you could post a sample that I could paste and use I'd appreciate it!
0
It doesn't have to be $variablename you can put here any naming for a variable that's the variable you can work with later in the code