-12

Is that possible to pass a JS variable to PHP ?

My code is :

document.getElementById('designation_' + i).value = '<?php echo $list[HERE]; ?>';

where I is in a for loop.

I want to echo the $list array in PHP with the index I of my JS (instead of HERE). First, is that possible? If yes, how?

Bharata
  • 13,509
  • 6
  • 36
  • 50
AjaxLoser
  • 31
  • 1
  • 9

1 Answers1

-2

You can not pass the JavaScript variable up to PHP to index the $list array. What you can do is to pass the whole array down to JavaScript as JSON encoded and then index into that.

See: Convert php array to Javascript

Community
  • 1
  • 1
Chris Buck
  • 745
  • 5
  • 15