user4246994
user4246994

Reputation:

How to push values to PHP array variable through JavaScript?

html output

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

Upvotes: 1

Views: 1652

Answers (2)

manuyd
manuyd

Reputation: 201

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'>

Upvotes: 2

Dennis Weidmann
Dennis Weidmann

Reputation: 1967

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?

Upvotes: 0

Related Questions