Passing a Value from PHP to Javascript Variable
<p>I've seen numerous posts on how to do this either saying to use <code>rawurlencode</code> in the php and <code>decodeURIComponent</code> in javascript or just use <code>json_encode</code>.  Neither work for me.  Hoping someone can see what I'm doing wrong:</p>

<p>I have an html button like this:</p>

<pre><code>&lt;button id="editbutton" onClick='edit(this, "&lt;?php echo htmlentities($_SERVER['REQUEST_URI']); ?&gt;", "&lt;?php echo $result_cameras[$i]["camera_type"]; ?&gt;", "&lt;?php echo rawurlencode($result_cameras[$i]["camera_name"]); ?&gt;")'&gt;Edit&lt;/button&gt;
</code></pre>

<p>I pass that into the javascript edit button:</p>

<pre><code>var edit = function(t, to, cameratype, cameraname, cameraquality, camerahash, camerastatus, emailnotice, camerasensitivity, axisuser, axispass, axisip, axisport)
{

if (mydiv.find("form").length) {
    mydiv.show();
} else {
    // fields
    var $myform = $("&lt;form id='EditCameraForm' name='' method='post' action='" + to + "'&gt;&lt;/form&gt;");
    var $myfieldset = $("&lt;fieldset&gt;&lt;legend&gt;Edit camera settings&lt;/legend&gt;&lt;/fieldset&gt;");
    var $myinput = $('&lt;input/&gt;').attr('type','hidden').attr('name','camera_type').val(cameratype);
    var $mylabel = $("&lt;label for='CameraName'&gt;Camera name:&amp;nbsp;&lt;/label&gt;");
    var $myinput2 = js('&lt;input/&gt;').attr('size','25').attr('name','camera_name').attr('id','CameraName').val(decodeURIComponent(cameraname));
    $myform.append($myinput, $mylabel, $myinput2);
...
}
...
}
</code></pre>

<p>I've tried using rawurlencode/decodeURIComponent as above and when I hit the edit button if the camera name is called: <code>a"a</code> (just testing the quotes) I get <code>a&amp;quot;a</code>.  Backslashes such as <code>a\b</code> just returns some weird characters back.</p>

<p>If I try:</p>

<pre><code>&lt;?php echo json_encode($result_cameras[$i]["camera_name"]); ?&gt; 
</code></pre>

<p>and don't put anything in the javascript code I get this error:</p>

<p><code>missing ) after argument list</code></p>

<p><code>edit(this, "/dashboard", "WEBCAM", ""a"a"", "0", "3dd10c49784e2207de1e1932958bfb...</code>
Where it is pointing to the ""a"a"".</p>

<p>Any suggestions?</p>
