php
  • javascript
  • onclick
  • echo
  • 2009-06-25 7 views 1 likes 
    1

    ma question est de savoir comment je peux faire écho ce la bonne façon parce que la variable dans la fonction onclick donne une erreur non définiemanière correcte de faire écho un lien avec un onclick javascript fonction

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

    Je veux l'utiliser dans une boucle pour obtenir une liste de utilisateurs en ligne pour le chat

    Merci, Richard

    Répondre

    1

    Essayez ceci:

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

    Si json_encode n'est pas disponible, essayez ceci:

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

    json_encode ?? ok, intéressant. Je vais essayer si le premier n'a pas fonctionné. –

    +0

    @Richard: 'json_encode' est requis pour obtenir une déclaration de chaîne JavaScript valide. – Gumbo

    +0

    @Gumbo: dans les deux cas, vous avez besoin de l'option ENT_QUOTES à htmlspecialchars() – gahooa

    6

    On dirait que vous manquez quelques citations:

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

    ou pour une sécurité accrue:

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

    celui-ci l'a fait, merci –

    +0

    @Richard Vous voudrez peut-être accepter cette réponse alors;) –

    +0

    quoi, y a-t-il un bouton à cliquer alors? –

    Questions connexes