uma uma - 5 months ago 30
HTML Question

Is there any way to pass PHP object as JavaScript parameter in HTML?

I do project using Laravel 5. I show table from view and I want to when click this link pass it is data value all data to JavaScript function. I am try to several way but cannot do it.

@foreach ($basl_officers as $basl_officer)
<td><a href="#" onClick="functionOne($basl_officer)" >{{ $basl_officer->officerName }} </a></td>
<td align='center'>
{!! Form::open(['method' => 'DELETE', 'route'=>['basl_officers_page.destroy',$basl_officer->id]]) !!}
<a href="{{route('basl_officers_page.edit',$basl_officer->id)}}" class="btn btn-default btn-sm"> <span class="glyphicon glyphicon-pencil"></span> </a> &nbsp &nbsp
<button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button>
{!! Form::close() !!}

JavaScript Code

<script type="text/javascript">
function functionOne(x) {
alert('You clicked the top text' + x);
function functionTwo() {
alert('You clicked the bottom text');


You could try this:

onClick="functionOne({{ json_encode($basl_officer) }})"