I wanna add elements to the array in laravel blade template. here is my script:
<script>
selected_arr = [];
</script>
I wanna get an array like [1,2,3]
, I tried to use array_push
, the code is here:
<script>
function select_array (id){
selected_arr=array_push(selected_arr, id);
}
</script>
the result of selected_arr
is still null. Can you please help me to figure it out? Many Thanks!
2
Answers
Your question is not clear, because laravel blade is ssr.
Client-side by using js:
If you need to share data with the server you need a controller behind it, then you need ajax calls to sync view variables with the contoller.
If you only need the array variable on client side you can use javascript function like