473,652 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript events with file input

Plater
7,872 Recognized Expert Expert
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:\sdgrthkzujh sfg" 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
3 2402
rnd me
427 Recognized Expert Contributor
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
7,872 Recognized Expert Expert
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 "sdfgtryhry h" 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
16,027 Recognized Expert Moderator MVP
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

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

Similar topics

9
4642
by: Phil Powell | last post by:
I am producing a form using PHP on the back end and Javascript on the front end. The resulting script will come to the browser as follows: <script> <!-- function selectAll() { moveElement = eval("document.imageForm.move" + ""); alert(moveElement); if (document.imageForm.select_all.checked) {
3
2679
by: Don | last post by:
How do I code the following Javascript to run in a PHP script? ------------------------- <script type="text/javascript" language="javascript"> // function passfile1path() { var path = document.processPictures.userfile1.value; document.processPictures.file1path.value = path; }
7
1973
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right frame.
14
5453
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
14
3300
by: horos | last post by:
hey all, I'm a heavy perl user, not so much a java script user, and was wondering... perl has an extremely nice utility called Data::Dumper, which allows you to dump out the contents of an arbitrary data structure. I'd like to do the same with javascript. print Data::Dumper(document)
24
6320
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
2
2103
by: Safalra | last post by:
Recently I've rewritten much of my old Javascript code to use DOM functions so that enhancements can be attached to documents without needing to alter the HTML code. I assumed that adding event handlers to document.body would have the same effect as adding those event handlers through attributes of the body element, but this turned out not to be the case for key events. Take this example page (IE-specific code removed): ...
19
2216
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? (in conjunction with css, you know, the usual...;) this is what is meant by "modern" javascript?? so how do folks feel about this who think javascript is so evil they disable it from their browsers?? do sites designed with "modern" javascript...
1
3440
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i have to made in my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type"...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.