uma uma - 1 year ago 76
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');

Answer Source

You could try this:

onClick="functionOne({{ json_encode($basl_officer) }})"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download