Frage

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(\" ;'=""
War es hilfreich?

Lösung

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>';

Andere Tipps

Something like this?

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top