perl / ajax / js / quoting question

S

seven.reeds

Hi,

I am not a js expert by any stretch and this might be a js question
more than perl so fingers crossed...

Ok, I am doing some ajax and have this '<input type='file"' input that
I am working on. It is accepting image files. When its value changes
I want to display the image in an associated DIV. I am building the
html and js lines in a perl script. THe relevant section looks like:

$HTML .= <<EOF;
<p><label for="IThumbnail">Path to Thumbnail</label>
<input type="file" name="IThumbnail" id="IThumbnail"
size=50
accept="image/gif,image/jpeg"
onchange="
document.getElementById('IThumbnailImageDiv').innerHTML
=
'<img src="file://' +
document.getElementById('IThumbnail').value +
'" alt="upload file" />'; return false; " /></p>

<div id="IThumbnailImageDiv"
style="float:left;
clear:both;">
</div>
EOF

I'm testing this with FireFox and have the js Console open. It tells
me that there are mis-matching quotes starting at: '<img

I have tried quoting the double quotes inside the IMG tag I am building
with "\" and "\\" but neither works. This has to be a simple mistake
but I am not seeing it.

help?
 
S

Sherm Pendley

seven.reeds said:
I am not a js expert by any stretch and this might be a js question
more than perl so fingers crossed...

Sorry - it is a JS question. The problem is with the JS code that you're
printing, not with the Perl code you're using to print it. If you pasted
that snippet directly into a static HTML file (with no Perl involved at
all), you'd get precisely the same error.

That said...

I would try putting the JS in a separate .js file, importing it with a
<script> element, and then calling it with a simple function call in your
onChange attribute. Nesting languages two and three deep tends to cause
problems - as you you've discovered here.

If you need more help with this, try comp.lang.javascript.

sherm--
 
S

seven.reeds

Thanks. I've been told from another source that what I am trying to do
is not legal in js anyway. According to this source trying to display
"local" images is considered a security risk. tsk

ciao
 
H

Hobo Salesman

seven.reeds said:
Thanks. I've been told from another source that what I am trying to do
is not legal in js anyway. According to this source trying to display
"local" images is considered a security risk. tsk

'file' URI is valid for browsers... <input type="file"> should give you
the absolute local path... I think some browsers even send the full
path to the server. If theres a check that keeps you from doing this
it's implemented in the browser not in JS. I'd test the code without
the AJAX/Perl, you went to this much trouble why not check it out? My
guess is it works in at least some browsers with some security
settings.

And post your results back here. Unless the off-topic thing bothers the
regulars.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top