0

In my file there is PHP inside javascript, for Add Row HTML. Below my current script :

 $(document).ready(function(){
  var i=1;
 $("#add_row").click(function(){
  $('#addr'+i).html("<td>"+ (i+1) +"</td><td><select name='room_manager_id["+i+"]' class='form-control' ><option value=''>--Choose--</option><?php 
    foreach ($resultCompany  as $rowx) { 
        ?><optgroup label='<?php echo $rowx->company_name?>'><?php
        $resultType = $this->md_calendar_view->selectAllRoomAvailable($start_date,$end_date,$rowx->company_id)?><?php 
        foreach ($resultType as $row) { 
            ?><option value='<?php echo $row->room_manager_id?>'><?php echo $row->room_manager_name." - ".$row->room_type_name." - ".$row->capacity_name." (".$row->capacity_number.") - ".$row->room_available." room(s) left";?></option><?php 
        }  ?><?php 
    } ?></optgroup></select></td><td><input type='text' name='booking_total_rooms["+i+"]' class='form-control'> </td>");
  $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
  i++;
  });
 $("#delete_row").click(function(){
     if(i>1){
     $("#addr"+(i-1)).html('');
     i--;
     }
});

it cause Uncaught SyntaxError: Unexpected token ILLEGAL but when i'm delete some php script (just to view where it is an error) it works perfectly. I'm delete this part :

<?php foreach ($resultType as $row) { ?><option value='<?php echo $row->room_manager_id?>'><?php echo $row->room_manager_name." - ".$row->room_type_name." - ".$row->capacity_name." (".$row->capacity_number.") - ".$row->room_available." room(s) left";?></option><?php }  ?>

regards and thanks.

Barmar
  • 741,623
  • 53
  • 500
  • 612
reefman
  • 143
  • 4
  • 13
  • You don't have PHP inside JS. PHP can hold JS code, because it's exeucted on the server and you can print JS code to be interpreted by the browser. But if you put PHP code inside JS nothing is going to happen. – Gonzalo Dec 11 '15 at 02:16
  • Does the web page have a `.php` extension? If not, it won't go through the PHP interpreter. Also, is it on a server? PHP scripts aren't run in local files. – Barmar Dec 11 '15 at 02:24
  • Okey i'll fiigure it out, it cames error when optgroup more than 1 , it will showing this error but if just one optgroup it works fine. thanks – reefman Dec 11 '15 at 02:47

0 Answers0