Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2007, 11:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default disabling submit button

I have an upload image form and that code works perfect.

My problem is I have added some javacript to disable the button after the submission. The disable will work fine but then the form will not submit and continue processing and uploading the image. I have tried a couple of different methods, I have used method 2 before and it works fine when it is not a enctype="multipart/form-data" form. Can anybody please help me resolve this.

<?php
if (isset($_POST['action_upload']) && $_POST['action_upload'] == 'Upload') {
//upload code works fine.
}
?>


METHOD 1 __________
<script language="JavaScript">
function disableForm(theform) {
    document.upload_frm.action_upload.disabled=true;
    return true;
}
</script>

<form action="upload_img.php" method="post" enctype="multipart/form-data" id="my_form" name="upload_frm">
Select Image: <input type="file" name="up_file"><br />
<input type="submit" name="action_upload" value="Upload" onclick='doSubmit(this.form, this);'>
</form>



METHOD 2 __________
<script language="JavaScript" type="text/javascript">
<!--
var clicked = false;

function doSubmit(frm, btn){
  if (clicked == false) {
    clicked = true;
    btn.disabled = true;
    btn.value='Please wait...';
     try {
            frm.onsubmit();
        }
        catch(e) {}
        frm.submit();
  }
}
 -->
</script>

<form action="upload_img.php" method="post" enctype="multipart/form-data" id="my_form" name="upload_frm">
Select Image: <input type="file" name="up_file"><br />
<input type="button" onclick='doSubmit(this.form, this);' value="Upload" name="action_upload">
</form>

Thanks
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
Disabling browser's "X" button farhanzia HTML Code Clinic 4 March 23rd, 2005 01:19 PM
Disabling browser's window "X" button farhanzia Classic ASP Professional 1 July 9th, 2003 06:29 PM
Disabling browser's "X" button farhanzia Javascript 1 July 9th, 2003 10:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.