problems with seding variables from PHP into JavaScript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Talex80
Forum Newbie
Posts: 5
Joined: Tue Nov 09, 2004 7:43 am
Contact:

problems with seding variables from PHP into JavaScript

Post 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).
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Talex,

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

Greetz Jolly.
Talex80
Forum Newbie
Posts: 5
Joined: Tue Nov 09, 2004 7:43 am
Contact:

Post by Talex80 »

i found... i've to use htmlentities() function

Code: Select all

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