?
Solved

Auto file input browse -> will not submit.

Posted on 2003-02-26
8
Medium Priority
?
448 Views
Last Modified: 2008-02-07
I want the page to launch a browse file dialogue when it opens. This works fine, though when you select a file and press the submit button - it doen't submit - it instead clears the file you just selected.
Then browsing and submitting will work properly.
here is my code...
---------------------------------------------------------

<html>
<head>
<title>File Upload</title>
</head>
<body>
Won't submit 1st time.
<form method="post" name="upload_form" enctype="multipart/form-data" action="http://somesite.com">
<input type="file" name="file_upload" ><br><br>
<input type="submit" name= "submit_button" value="SUBMIT" >
</form>
<script language="javascript">
<!--
     window.document.upload_form.file_upload.click();
        // [auto submit]
        // window.document.upload_form.submit();
//-->
</script>
</body>
</html>

---------------------------------------------------------
Thanks for your help;
Lachlan.

PS: Also if I try to submit the form (where it says [auto submit] above) - I get access denied error. If you answer this too I give you a bonus 150 pts.


0
Comment
Question by:lachie99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:rbagdonas
ID: 8031271
Here you go.  Autosubmits and everything.


<html>
<head>
<title>File Upload</title>
</head>
<body>
Won't submit 1st time.
<form method="post" ACTION="imageupload.asp" ENCTYPE="multipart/form-data" name="test" id="test">
<input type="file" name="File1" size="45" style="width:530px;" onchange="Test();">
<br><br>
<input type="button" name= "submit_button" value="SUBMIT" onclick="Test();">
</form>
<script language="javascript">
    window.document.test.File1.click();
   
    function Test()
          {
               if ( document.test.File1.value == "" )
                    {
                         alert("Please select an file.");
                         document.test.File1.focus();
                         return false;
                    }

               document.test.submit();
          }
</script>
</body>
</html>


R
0
 
LVL 2

Expert Comment

by:rbagdonas
ID: 8031290
Damnit. It worked once, but after subsequent tries it failed.  I removed the auto-click and it seems to work fine.  Hang on.  Making a quick change.

R
0
 
LVL 30

Expert Comment

by:third
ID: 8031301
"I get access denied error."

you get this message because of security reasons.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
rbagdonas earned 1500 total points
ID: 8031324
OK.  Here is the issue.  You get an access violation (at least in IE) when you try to force the auto popup from the load.  I have researched it and nothing comes up so sorry.

I have tried onload, in a timeout situation, nothing works.  At least this form autosubmits when they select a file.

<html>
<head>
<title>File Upload</title>
</head>
<body>
Won't submit 1st time.
<form method="post" ACTION="test.html" ENCTYPE="multipart/form-data" name="test" id="test">
<input type="file" name="File1" size="45" style="width:530px;" onchange="Test();">
<br><br>
<input type="button" value="Submit" onclick="Test();">
</form>
<script language="javascript">
    document.test.File1.focus();

    function Test()
          {
               if ( document.test.File1.value == "" )
                    {
                         alert("Please select an file.");
                         document.test.File1.focus();
                         return false;
                    }

               document.test.submit();
          }
</script>
</body>
</html>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 8031698
Hello lachie99,

try this:
<html>
<head>
<title>File Upload</title>
<script>
function startSelect(){
 document.upload_form.file_upload.click();
 window.setTimeout(document.upload_form.submit,3000);
}
</script>
</head>
<body onLoad="startSelect()">
Won't submit 1st time.
<form method="post" name="upload_form" enctype="multipart/form-data" action="http://somesite.com">
<input type="file" name="file_upload" ><br><br>
</form>
</body>
</html>



0
 

Author Comment

by:lachie99
ID: 8038028
Thanks for your suggestions -> though so far none of the examples submitted work...

rbagdonas -
The second example you sent doesn't open the file browse dialogue when the page opens.

zvonko -
Your example clears the selected file from the input field when it submits the form.

Does it work on your guys' browsers? I have IE6 on Windows XP.
Any other ideas?




0
 

Author Comment

by:lachie99
ID: 8038046
Oops sorry rbagdonas - I just read your comment on your 2nd submission. Thanks for your efforts.
0
 

Author Comment

by:lachie99
ID: 8038642
OK - I finally got this to happen...

I put the form with upload input in a hidden frame off screen. This frame is present when the main frame is loaded.

The JavaScript on the main frame dynamically clicks the upload button on the hidden frame.
Then immediately focuses the file input as well.
The file input has an onFocus event and when this is called it submits the form...

Not very elegant - though it works...

I'm gonna give the points to rbagdonas for his insight and research....

Thanks
Lachlan.


Thanks
Lachlan.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question