Page 1 of 1

problems with seding variables from PHP into JavaScript

Posted: Mon Nov 22, 2004 8:15 am
by Talex80
hi all,

i've such kind of problem... please have a look.

Code: Select all

<html>
<head><title>Sample code</title>
</head>

<script language="JavaScript">

function render(text)&#123;

            document.write(text);
&#125;

</script>

<?
    $x = 'input name="save"';      //  is not working
    $x1 = 'input name="not"';    //  is not working
    $x2 = 'input name=not';        //  working


?>

<body>
    <input name="save" id="butt_save" type="button" value="Save as HTML1" onClick="render('<?php echo($x);?>")'>

    <br><br><br>
    <!--<input name="save" id="butt_save" type="button" value="Save as HTML2" onClick="alert('<?php echo $x1;?>')">-->
</body>

</html>
it's rendered when we've no slashes or commas (i.e plain text).

Posted: Mon Nov 22, 2004 8:36 am
by jollyjumper
Hi Talex,

Try \\"not\\" (so not with one \ but two \)

Greetz Jolly.

Posted: Mon Nov 22, 2004 8:44 am
by Talex80
i found... i've to use htmlentities() function

Code: Select all

onClick="render('<?php echo htmlentities($x) ;?>")'>