Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a DOM element by id in Javascript code embedded in PHP when using tpl (Smarty)?
    primarykey
    data
    text
    <p>Objective: To be able to load a user selected image file in a resizeable div to allow resizing of image before submitting (using a jQuery resizable plugin). </p> <p>1) The layout of the view is defined in upload_myimage.tpl.html (snippet shown below).</p> <p>2) It is initialized to show an arbitrary image in a div which is set to "resizeable". The image displays and the resizing works.</p> <p>3) After choosing an image file and clicking on "Upload File" (a button in an HTML Form), the PHP function update_mypicture() (snippet shown below) is called to replace the aforementioned image. Error on line 24 of upload.php: Uncaught TypeError: Cannot set property 'onload' of null. img for some reason is returned as null. Any ideas why?</p> <p>-- snippet of tpl code --</p> <pre><code>&lt;div id ="box"&gt; &lt;img src="/image/logo.jpg" width="100%" height="100%" id="image"/&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $("#box").resizable(); &lt;/script&gt; </code></pre> <p>-- snippet of php code --</p> <pre><code>&lt;?php if($_POST['submitScaleName'] == "Submit") { ?&gt; &lt;script type="text/javascript"&gt; function scale_mypicture(pic){ var img = parent.document.getElementById("image"); // img is returned as null img.setAttribute("src", pic); var memeFilename = parent.document.getElementById("memeFilename"); memeFilename.value = "&lt;?php echo $_FILES['file']["name"]; ?&gt;"; } parent.document.getElementById("img_filename").value = ""; scale_mypicture("&lt;?php echo '/image/'.$_FILES['file']["name"]; ?&gt;"); &lt;/script&gt; &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload