admin管理员组

文章数量:1356914

my question is how I can echo this the right way because the variable in the onclick function gives out a undefined error

$openchat="<a href='javascript:void(0)' onClick='return chatWith(" . $livenaam .")'>" . $livenaam . "</a><br>";

echo $openchat;

I want to use it in a loop to get a list off users online for the chat

Thanks, Richard

my question is how I can echo this the right way because the variable in the onclick function gives out a undefined error

$openchat="<a href='javascript:void(0)' onClick='return chatWith(" . $livenaam .")'>" . $livenaam . "</a><br>";

echo $openchat;

I want to use it in a loop to get a list off users online for the chat

Thanks, Richard

Share Improve this question asked Jun 25, 2009 at 17:16 RichardRichard
Add a ment  | 

2 Answers 2

Reset to default 6

Looks like you are missing some quotes:

$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . $livenaam ."\")'>" . $livenaam . "</a><br>";

or for increased security:

$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . htmlspecialchars($livenaam,ENT_QUOTES) ."\")'>" . htmlspecialchars($livenaam,ENT_QUOTES) . "</a><br>";

Try this:

'<a href="javascript:void(0)" onclick="return chatWith(' . htmlspecialchars(json_encode($livenaam)) . ')">' . htmlspecialchars($livenaam) . '</a><br>'

If json_encode is not available, try this:

'<a href="javascript:void(0)" onclick="return chatWith(' . htmlspecialchars('"'.addslashes($livenaam).'"') . ')">' . htmlspecialchars($livenaam) . '</a><br>'

本文标签: phpcorrect way to echo a link with a onclick javascript functionStack Overflow