+ 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!

19th Apr 2019, 11:20 AM
Arman A
Arman A - avatar
13 Respostas
+ 7
you should use AJAX
20th Apr 2019, 10:40 AM
Salif Mehmed đŸ‡čđŸ‡·đŸ‡§đŸ‡Ź
Salif Mehmed  đŸ‡čđŸ‡·đŸ‡§đŸ‡Ź - avatar
+ 2
Send it as a request to the server and Prozess it from there on
19th Apr 2019, 8:01 PM
Lexfuturorum
Lexfuturorum - avatar
+ 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
21st Apr 2019, 11:03 AM
Logomonic Learning
Logomonic Learning - avatar
+ 1
Arman A sry I lost attention of that converation. First you'll need to setup a HTML Form like Mike already linked After that you can extract the variable with: $variablename = $_POST['namepropfromhtml'] And Prozess it further from there. If I don't forget about this I'll post more code here later
20th Apr 2019, 10:14 AM
Lexfuturorum
Lexfuturorum - avatar
+ 1
Salif Mehmed i think if we go into that he's more confused than before.
20th Apr 2019, 10:49 AM
Lexfuturorum
Lexfuturorum - avatar
20th Apr 2019, 2:19 PM
Lexfuturorum
Lexfuturorum - avatar
+ 1
Monical and what's about ajax
21st Apr 2019, 1:31 PM
Lexfuturorum
Lexfuturorum - avatar
0
Feichtinger Andreas could you please elaborate with code so I can add it and try it out? how should I request the variable?
19th Apr 2019, 10:31 PM
Arman A
Arman A - avatar
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/
20th Apr 2019, 2:35 AM
Mike
Mike - avatar
0
Dhivya pls read the answeres before you post something that's already there and therefor just spam
20th Apr 2019, 2:02 PM
Lexfuturorum
Lexfuturorum - avatar
0
Feichtinger Andreas I have add that code into the php file but can you clarify $variablename I should put the JavaScript value?
20th Apr 2019, 2:05 PM
Arman A
Arman A - avatar
0
Mike if you could post a sample that I could paste and use I'd appreciate it!
20th Apr 2019, 2:05 PM
Arman A
Arman A - avatar
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
20th Apr 2019, 2:07 PM
Lexfuturorum
Lexfuturorum - avatar