views:

20

answers:

1

My idea : when click a filename will get the path of file ,

then create a form and submit this form,

but i don't know how to submit ,

when submit , undefined form cause elements was created at same time

help me, thank !

<p onclcick='startUpload(this.value)'>PATHTOFILE<p>

function startUpload(file)
        {
          var form = '<form name="form_upload" method="post" enctype="multipart/form-data" action="upload.php">';
          form +=   '<input type="file" name="upload_logo"/>';
          form += '</form>';

          // code to submit . i don't know how :(
        }
+1  A: 

first off, p tags have no value. this.value needs to change to this.get("text").clear(); second, you cannot pass on the value to the file dialogue object from an external source - else, what's to stop you from changing that value to say, c:\autoexec.bat or /etc/passwd or similar, you get the idea - a major security flaw in the design.

so the form creation is fine but it needs to be user driven - they select the file, they submit (or you submit on select for the file input).

to plain submit using your current html you'd do:

new Element("div", {
    htm: form
}).inject(targetDiv);

targetdiv.getElement("form[name=form_upload]").submit();

if you need to ajax it, then say so - there are some methods available through html5 or an iframe shin or a flash uploader that can allow you to do so without a page reload, neither of which qualifies for progressive enhancement though.

good luck

Dimitar Christoff
very thank for your suggestion !
Chameron