Is there any way to pass a javascript variable to a php function or simply assign a js variable to a php variable....???
test("asdas"); I need to update "asdas" to a dynamic value, i.e of the form,
Is there any way to pass a javascript variable to a php function or simply assign a js variable to a php variable....??? test("asdas"); I need to update "asdas" to a dynamic value, i.e of the form, |
|||||||||||||||||||||
|
You can pass value from js to PHP using ajax request or add js value to URL and then reload page. Variant #1 (using ajax): JS side (jquery)
PHP side
Variant #2 (with page reload): JS side
PHP side
|
|||||||||||||||||
|
When you want to send something from JS to PHP or from PHP to JS, use Ajax. If PHP already knows the value it wants to send to JS when it's delivering the page, you can also embed it in JS:
Edit: As porneL said, you should not put data in the page that way without escaping it to avoid opening XSS holes. Oh, and if you use AJAX, also pay attention on not making ajax data |
|||||||||||||
|