简体   繁体   中英

How to push values to PHP array variable through JavaScript?

HTML输出

this this my page also i have one form also,it have a clb button for every alert,i have written a javascript function for each button(by looping) to pass the ticket id , so when i click clg this should store in php array variable to keep every ticket id,below is button code and javascript function

<input value="clb" onclick="clb_this('116305');" type="button">

 function clb_this(vl)
  {
   alert(vl);
   }

this value should store in below variable

  `<input type='hidden' name='tic_array[]' id='tic_array'>`

please share your ideas,thanks

try the below code

It will store the value in tic_array with comma separated and you can convert it into array with php explode function

 <script>
var clb = new Array();
function clb_this(vl) {
    clb.push(vl);
   document.getElementById("tic_array").value = clb;

}
</script>

<input type='hidden' name='tic_array' id='tic_array'>

Well its just my thoughts... If I understand you right, you want to get values from a javascript variable into an php array right?

Javascript is executed client sided and dynamically, so you could post your value per REST service to a php that receives it, each time user clicks the button...

In the php you have to create a session var to store your array and just push the value into it, every time the php is called.

Does that give you a hint?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM