View Full Version : Put Event Handler in Submit button
11-12-2004, 09:13 PM
Basically what we have here is some code that displays and image when the submit button is clicked.
I have been attempting take this event and place it within the input tag. The reason for this is that when the submit button is placed within a form the button submits and overlooks the load image onclick.
The code below works as is. Of course, as soon as you place the submit button between form tags the problem appears.
Any help would be greatly appreciated!
function loading() //call this function onclick
document.getElementById("DIV1").style.display = ""; //this will actually
<input type="submit" value="test" name="B1" onclick="return loading();">
<div id="DIV1" style="display:none">
<img src='N2B_3E2.gif' />
11-12-2004, 09:18 PM
I'm sorry, what's the problem with this script? The only thing I can see is that when you click the submit button and the image appears, you don't have long to see it before you are taken to a different page.
11-12-2004, 09:35 PM
I'm sorry, I should have explained a bit more about the application of this script. It is going to be used for a PHP uploader and I was planning on using an animated GIF as the image which show's a looped "progress bar" until the upload summary page loads. So, there is technically no problem with the code listed above, it is just that it doesn't work for my situation.
11-13-2004, 04:51 PM
OK, so what actually needs to be changed? If N2B_3E2.gif is your animation then I don't know why it needs changing at all.
11-13-2004, 06:26 PM
I want to take the code from my first post from this (example of calling a function):
alert("I am displayed from a function");
To this (event handler running from within the submit button):
<input type="submit" value="Submit" onClick="alert('You clicked the submit button!')">
As I mentioned before, in my original code the image loading is overlooked because the submit button is busy submitting the data (uploading the file in my uploader). If I can place the event handler in the submit button the image will load while the upload proceeds. Typically the files that are uploaded are large enough that there is at least 30 seconds before the upload summary page loads. So you would in fact get a change to see the image load.
Thanks again for any assistance.
11-13-2004, 07:43 PM
Ah, I see. In that case do this:
<input type="submit" value="test" name="B1" onclick="document.getElementById('DIV1').style.display='block';return true;">
11-13-2004, 08:07 PM
Thank you! That is exactly what I was looking for. It works perfectly.
Your patience and help have been greatly appreciated! :)
11-13-2004, 11:33 PM
Happy to help. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.