Assign js variable value to php variable
I have declared a javascript variable , Show
And unable to assign that value to php variable;
I know Ajax may be the solution of my problem. But i don't know how to use Ajax and solve the problem.
Punit Gajjar 4,6217 gold badges32 silver badges64 bronze badges asked Feb 7, 2014 at 5:37
2 Using Cookie is the better solution i think -
answered Oct 12, 2016 at 19:58
1 Try using ajax with jQuery.post() if you want a more dynamic assignment of variables. The reason you can't assign a variable directly is because they are processed in different places. It's like trying to add eggs to an already baked cake, instead you should send the egg to the bakery to get a new cake with the new eggs. That's what jQuery's post is made for. Alert the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).
answered Feb 7, 2014 at 6:31
I have a better solution: Here, in the .php file, I have a variable called javascriptVar. Now, I want to assign the value of javascriptVar to my php variable called phpVar. I do this by simply call javascript variable by document.writeln in the script tag.
answered Oct 13, 2020 at 4:11
Nazmul81Nazmul81 1321 gold badge3 silver badges12 bronze badges 3
answered Mar 26, 2017 at 19:39
1
answered Sep 15, 2017 at 6:46 1 I guess you can use cookies for it. 1) First add a cookie jquery plugin. 2) Then store that window width in a cookie variable. 3) Access your cookie in PHP like $_COOKIE['variable name']. http://www.w3schools.com/php/php_cookies.asp answered Feb 7, 2014 at 5:53
hizbul25hizbul25 3,7394 gold badges25 silver badges37 bronze badges Javascript will be interpreted in Client's browser and you can not assign it to PHP variable which is interpreted on SERVER . Feasible Solution : You can submit the Javascript value via ajax or through form submit. answered Feb 7, 2014 at 5:58
Dimag KharabDimag Kharab 4,4211 gold badge21 silver badges45 bronze badges You should see these links: Assign Javascript value to PHP variable Passing Javascript vars to PHP Or you can use AJAX request or POST and GET methods to achieve this. Snippet below may helpful for you:
answered Mar 26, 2014 at 9:10
Sohail xIN3NSohail xIN3N 2,8812 gold badges28 silver badges29 bronze badges Use this code to solve your problem.
answered Aug 25 at 10:42
answered Jun 27, 2021 at 13:52
1 Please use this code and it will works fine in all cases.
answered Jul 13, 2021 at 5:01
1 Can we assign JavaScript variable to PHP variable?Javascript will be interpreted in Client's browser and you can not assign it to PHP variable which is interpreted on SERVER .
How do I pass JavaScript variable to PHP?The way to pass a JavaScript variable to PHP is through a request. This type of URL is only visible if we use the GET action, the POST action hides the information in the URL. Server Side(PHP): On the server side PHP page, we request for the data submitted by the form and display the result. $result = $_GET [ 'data' ];
How use JavaScript variable on same page in PHP?You can easily get the JavaScript variable value on the same page in PHP. Try the following codeL. php echo "
Bài Viết Liên QuanQuảng CáoCó thể bạn quan tâmToplist được quan tâm#1
Top 9 tập bản đồ lớp 8 bài 31 20235 tháng trước#2
Top 6 kết quả thi hsg đà nẵng 2022 20235 tháng trước#3
Top 9 tủ nhựa đài loan 4 cánh 3d 20235 tháng trước#4
#5
Top 8 tìm việc làm tiện, phay bảo q7 20235 tháng trước#6
#7
#8
Top 2 bài the dục phát triển chung lớp 6 2022 20235 tháng trước#9
Top 3 bài giảng vũ điệu sắc màu (lớp 4) 20235 tháng trướcQuảng cáoXem NhiềuQuảng cáoChúng tôiTrợ giúpBản quyền © 2021 Xây Nhà Inc.
|