How to declare php variable in javascript
I want to declare a PHP variable (most preferably a session variable) inside a javascript function. Show Here is my html
and here if my javascript function but this is not working.
Basically on option change, I want a session variable to hold the value of option whichever is selected. Is there any way to do it? asked Oct 28, 2015 at 5:21
6 You can not set php variable using javascript, use Ajax instead. Actually php is a server side language and is executed until your webpage if fetching data from server as soon as your page gets completely loaded you loose the access to php variables. You can achieve this only by AJAX And to do it with ajax on your current page you can write a function like
and then on http://url.of/somepage/ you can do
answered Oct 28, 2015 at 5:28
ArpitaArpita 1,3541 gold badge15 silver badges35 bronze badges 1 try this code:-
answered Oct 28, 2015 at 5:22
4
answered Oct 28, 2015 at 5:27
Raja CRaja C 1391 silver badge12 bronze badges 1 Sometimes, you may need to declare dynamic JS variables using PHP. One thing you can do is to manually write the JS code as following.
Enter fullscreen mode Exit fullscreen mode But, we can create a function to do this easily with a better data types support.
Enter fullscreen mode Exit fullscreen mode This function requires an PHP array, which contains key/value pairs which are the Javascript variable name and the value. Also, this function automaically creates Javascript variables according to the data type of the PHP variable. PHP Arrays will be converted into JSON format. If you don't need the ' Bài Viết Liên QuanQuảng CáoCó thể bạn quan tâmToplist được quan tâm#2
#3
#4
Top 6 thử thách thần chết thuyết minh phần 2 20235 tháng trước#5
#6
Top 5 áo khoác nam quảng châu cao cấp 20235 tháng trước#7
#8
Top 9 mẫu đồng phục công sở đẹp 2022 20235 tháng trước#9
Top 5 ốp lưng iphone 13 pro bảo vệ camera 20235 tháng trướcQuảng cáoXem NhiềuQuảng cáoChúng tôiTrợ giúpBản quyền © 2021 boxhoidap.com Inc.
|