By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,575 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,575 IT Pros & Developers. It's quick & easy.

javascript events with file input

Plater
Expert 5K+
P: 7,872
I am having a spot of trouble with a little situation.
I want to make the submit invisible on a submit so that the user cannot keep clicking on it while the server is receiving the file transfer.
The webpage will change after the submission, so un-hiding of the button should not be an issuse. Or so I thought.

Given a rough puesdo code of:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <script type="text/javascript>
  4. function HideMe()
  5. {
  6.    document.getElementById("mysubmit").style.visibility="hidden";
  7.    document.getElementById("coversheet").style.visibility="visible";
  8. }
  9. </script>
  10.  
  11. <form>
  12. <input type="file" id="myfile" />
  13. <br/>
  14. <input type="submit" id="mysubmit" onclick="HideMe()">
  15. <span id="coversheet" style="visibility:hidden;">Please wait...</span>
  16. </form>
  17.  
  18.  
  19.  
Now this works great, as long as the form submits.
However, if you consider that a user can enter "sdgrthkzujhsfg" into the file upload textbox and click submit, we run into the problem.
The javascript onclick fires and changes the visibility of the two objects, BUT it never actually makes a page submission because "sdgrthkzujhsfg" is inccorect? (Note: "c:\sdgrthkzujhsfg" triggers a submission with roughly the same as "no file") So the user is left with no submission button and a "please wait...", even though the website is not doing any processing.

I have also tried the OnSubmit() event with the same result.
I found success(for the most part) with onbeforeunload() on the body element, but as I understand it there is some standards issues between browsers?
I tried using the onunload() event but you never see the result (the visibility does not change)

Can anyone recomend anything to only hide the submit button when a submit is actually going to happen? And not when their is the "sdgrthkzujhsfg" type situation?
Nov 17 '08 #1
Share this Question
Share on Google+
3 Replies


rnd me
Expert 100+
P: 427
why don't you simply unhide it when the page loads, in an onload event.

it wont hurt anything to unhide an already visible tag...
Nov 18 '08 #2

Plater
Expert 5K+
P: 7,872
why don't you simply unhide it when the page loads, in an onload event.

it wont hurt anything to unhide an already visible tag...
The page doesn't reload with "sdfgtryhryh" in the file input, it just doesn't do anything. Except fire all the javascript events like it WOULD do something
Nov 18 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You could try a hidden file upload. If it fails or times out, make the element visible again.

Note that you wouldn't have this problem in Firefox 3 because the file input field is read-and-click-only.
Nov 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.