Another Opera Javascript question

T

Tim Slattery

I'm (still) using Stickman's multiple file upload script. That results
in some number of <input type="file"...> elements, one of which has no
value. My file upload backend doesn't like empty elements, so I want
to stop that one from uploading.

So I have a Javascript that steps through the <input type="file"...>
elements, finds the one where value="", and sets disabled=true for
that element. On Safari, IE, and Firefox (and Netscape's Firefox mode)
this works, the disabled element is not submitted. On Opera, the empty
element is submitted and my backend barfs.

Is Opera somehow idiosyncratic in the way it handles this? Do I need
to set some other property?
 
T

tomtom.wozniak

I'm (still) using Stickman's multiple file upload script. That results
in some number of <input type="file"...> elements, one of which has no
value. My file upload backend doesn't like empty elements, so I want
to stop that one from uploading.

So I have a Javascript that steps through the <input type="file"...>
elements, finds the one where value="", and sets disabled=true for
that element. On Safari, IE, and Firefox (and Netscape's Firefox mode)
this works, the disabled element is not submitted. On Opera, the empty
element is submitted and my backend barfs.

Is Opera somehow idiosyncratic in the way it handles this? Do I need
to set some other property?

It seems to work for me in Opera. Please give some more info so I can
help!

Version 9.25
Build 8827
Platform Win32
System Windows XP
Java Sun Java Runtime Environment version 1.5
XHTML+Voice Plug-in not loaded
Browser identification Opera/9.25 (Windows NT 5.1; U; en)

This is what I came up with (see below) - any disabled fields do not
make it to the server (Apache/1.3.27). If I choose 1 file, only 1
file is posted: file1=dialog.ini. If I choose no files, no info is
posted. This works in IE7, FireFox, and Opera.

<!-- typefile.html -->

<form name="filepost" id="filepost" method="POST"
onSubmit="magicallyRemoveEmptyFieldsFromPost();"
action="http://localhost/cgi-bin/envpost.cgi">
<input name="file1" id="file1" type="file" /><br>
<input name="file2" id="file2" type="file" /><br>
<input type="submit" value="Post it!" />
</form>

<script>
function magicallyRemoveEmptyFieldsFromPost() {
var f = document.filepost;
for ( var i=0; i<f.elements.length ; i++ )
if ( f.type=='file' && f.value=='' ) f.disabled=true;
}
</script>

-Tom Woz
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top