문제

What I'm doing wrong? I want to show an alert function or message, but it does not work:

echo"<nm>".ucfirst($sd->fname)."&nbsp;".ucfirst($sd->sname)."<input type='button' id='$sd->id' value='Add Friend'  style='float:right';' onclick='alert(\'Clicky!\')'/><br></nm>";

When I view the source, it looks like below

clicky!\')'="" onclick="alert(\" ;'=""
도움이 되었습니까?

해결책

Be careful with the quotes / double quotes.

echo "<nm>".ucfirst($sd->fname)."&nbsp;".ucfirst($sd->sname).'<input type="button" id="'.$sd->id.'" value="Add Friend" style="float:right;" onclick="alert(\'Clicky!\');" /><br></nm>';

다른 팁

Something like this?

echo ("<a href='#' onclick='alert(\'Clicky!\')>" . ucfirst($sd->fname) . " " . ucfirst($sd->sname) . "</a>");

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top