Writing HTML code in Javascript inside a PHP code -


i need write in php, inside javascript portion code, hidden input tag javascript array need pass php code ..

this sample code ...

    echo '<script type="text/javascript">';      <other javascript code .... >      echo 'arr_selections_json = json.stringify(arr_selections);';     echo 'document.write("<input type="hidden" name="arr_selections_json" value="+arr_selections_json+" />")'; 

this code doesn't work .... suggestions? thank in advance .. .

you need js-escape double quotes inside argument of document.write() e.g.

echo 'document.write("<input type=\\"hidden\\" name=\\"arr_selections_json" value=\\"" + arr_selections_json + "\\" />")'; 

also, i've had recent weird cases, document.write wouldn't consider closing slash (/>), whereas it's html-5 compliant. had escape backslash closing slash.


Comments