0
echo"<div class='btn-likes'><input type='button' title='".ucwords($str_like)."' class='".$str_like."' onClick='addLikes(".$tutorial['id'].",".$str_like.")' /></div>";

Output from above code is :

<input title="Like" class="like" onclick="addLikes(51,like)" type="button">

Output what I want is :

<input title="Like" class="like" onclick="addLikes(51,'like')" type="button">

apostrophe is missing in onclick="addLikes(51,'like')"

I have try :

echo"<div class='btn-likes'><input type='button' title='".ucwords($str_like)."' class='".$str_like."' 
          onClick='addLikes(".$tutorial['id'].",'".$str_like."')' /></div>";

And the output is so viewy :

<input title="Like" class="like" onclick="addLikes(51," like')'="" type="button">

Anyone can help me ?

2 Answers 2

2

You need to escape the quotes:

echo '<div class="btn-likes"><input type="button" 
    title="'.ucwords($str_like).'" class="'.$str_like.'" 
    onClick="addLikes('.$tutorial['id'].',\''.$str_like.'\')" /></div>';
Sign up to request clarification or add additional context in comments.

Comments

2

Here how you can modify your code using some quotes escaping with \:

echo '<div class="btn-likes">
          <input type="button" title="' . ucwords($str_like) . '" class="' . $str_like . '" onClick="addLikes(' . $tutorial['id'] . ", '" . $str_like . "')\"/>
     </div>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.