subhra subhra - 7 months ago 11
PHP Question

Getting error while passing alphaneumeric value as parameter inside function using PHP and Javascript

I am getting one error while passing any alphanumeric value inside function using PHP and Javascript.

error:

category.php:235 Uncaught SyntaxError: missing ) after argument list


I am explaining my code below.

<?php
foreach ($listdata as $v) {
$id = '15rf67';
$edit = 1;
$del = 0;
echo "<tr>
<td>" . $counter++ . "</td>
<td>" . $v['cat_title'] . "</td>
<td>
<select class='form-control' id='status1' name='status1' style='height:23px; padding:0px;'>
<option value=''>Select Status</option>
<option value='1' " . ($v['status'] == '1' ? 'selected' : '') . ">Enable</option>
<option value='0' " . ($v['status'] == '0' ? 'selected' : '') . ">Disable</option>
</select>
</td>
<td>
<img src='uploads/" . $v['image'] . "' name='pro' border='0' style='width:50px; height:50px; border:#808080 1px solid;' />
</td>
<td>
" . $v['cat_description'] . "
</td>
<td>
<button type='button' class='btn btn-xs btn-green outlinedivnone' data-placement='top' title='' data-original-title='Edit' onClick='javascript:changeOfActionMenu($id,$edit)'><i class='fa fa-pencil'></i> </button>
<button type='button' class='btn btn-xs btn-danger outlinedivnone' data-placement='top' title='' data-original-title='Delete' onClick='javascript:changeOfActionMenu($id,$del)'><i class='fa fa-times'></i> </button>
</td>
</tr>";
}
?>


Here i am getting the error in this
<button type='button' class='btn btn-xs btn-green outlinedivnone' data-placement='top' title='' data-original-title='Edit' onClick='javascript:changeOfActionMenu($id,$edit)'><i class='fa fa-pencil'></i> </button>
line.when i am setting the $id value like
1,2..
this error is not coming but i need to pass the Alphanumeric value like
15rf67
.Please help me.

Answer

You have to place quote around $id, something like that

<button type='button' class='btn btn-xs btn-green outlinedivnone' data-placement='top' title=''   data-original-title='Edit' onClick='javascript:changeOfActionMenu(\"".$id."\",$edit)'><i class='fa fa-pencil'></i> </button> 

<button type='button' class='btn btn-xs btn-danger outlinedivnone' data-placement='top' title=''  data-original-title='Delete' onClick='javascript:changeOfActionMenu(\"".$id."\",$del)'><i class='fa fa-times'></i> </button>