0

I am trying to put a div into append but I am always getting SyntaxError: missing ) after argument list

My div look like

<div class='col-md-6'>
     <div class='form-group'>
          <?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?>
      </div>
     <div class='form-group'>
           <?= $this->Form->control('phone_number',['class'=>'form-control']); ?>
     </div>              
</div>

I have tried in append like below

$('#cform').append("<div class='col-md-6'><div class='form-group'><?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?></div><div class='form-group'><?= $this->Form->control('phone_number',['class'=>'form-control']); ?></div></div>");

I am not getting any syntax error here, How can I solve this ?

Satu Sultana
  • 527
  • 1
  • 11
  • 23
  • You are embedding PHP code inside of a JS string. – Greg Schmidt May 15 '19 at 15:15
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Greg Schmidt May 15 '19 at 15:15

1 Answers1

0

You can Use back tick `

$('#cform').append(`<div class='col-md-6'><div class='form-group'><?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?></div><div class='form-group'><?= $this->Form->control('phone_number',['class'=>'form-control']); ?></div></div>`);

Back tick may be not support in IE, So you can use "\" before space

Example :

<div class="form-group">\
  <?= $this->Form->control('user_id', ['options' => $users,'class'=>'form-control']);?>\
</div>\
<div class="form-group">\
<?= $this->Form->control('phone_number',['class'=>'form-control']); ?>\
</div>\
Alimon Karim
  • 4,354
  • 10
  • 43
  • 68