Skip to content
Advertisement

String in javascript function argument returns “Unexpected end of input”

I have ajax request function

 function Reject(id, scomment)
  {
      jQuery.ajax({
       type: "POST",
       url: "reject.php",
       data: {id: id, Scomment: scomment},
       cache: false,
       success: function(response)
       {
        location.reload();
       }
     });
 }

There is html from my php loop

<div class="modal-footer">
<textarea id="Scomment" name="Scomment" cols="40" rows="5" class="form-control"></textarea>
<button type="button" class="btn btn-danger" data-dismiss="modal" onClick="Reject('.$row['id'].', "sample text");">Reject</button>
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>

So..

If i will use string.

onClick="Reject('.$row['id'].', "sample text");"

console returns Uncaught SyntaxError: Unexpected end of input

But.. If i will use any number instead of “sample text”

onClick="Reject('.$row['id'].', 262434);"

It works.

I am newbie and kindly please support me guys.

Advertisement

Answer

You just have to escape your double quotation, this error happens because the starting and ending quote will not match with the current implementation.

Like this:

onClick="Reject('.$row['id'].', "sample text");"

Or use single quote instead.

onClick="Reject('.$row['id'].', 'sample text');"
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement