Jump to content

Submit button not being detected


Yesideez

Recommended Posts

Hi, I have a script and the submit button was working absolutely fine until I added the following Javascript:

  <script language="javascript" type="text/javascript">
    function disableForm(theForm) {
      if (document.all || document.getElementById) {
        for (i = 0; i < theform.length; i++) {
          var tempobj = theform.elements[i];
          if (tempobj.type.toLowerCase() == "submit") {
            tempobj.disabled = true;
            tempobj.value = "Please Wait";
            tempobj.style.background="#ff6666";
          }
        }
        return true;
      }
    }
  </script>

The HTML for the submit button is:

<input type="submit" name="subsend" value="Send Email" onClick="disableForm('theform');return true" class="gadbtn" />

I need to disable the button, change the text and the background color because the script can hang for a few seconds while files are being uploaded when clicked - have I done something wrong here?

 

(If I change the HTML part to return false the script just hangs with a red button :(

Link to comment
Share on other sites

sorry if i seem blunt but... no, its not.

 

let me explain;

 

this code you posted in the problem. so if that code was not there the "PHP" could function properly, this problem code is written in javascript, of which im really not familiar with. this is afterall a phpfreaks forums.

-----

 

onto your problem: you want to disable the button after the form is submitted so it cannot be submitted more than once.

 

for the solution read my post. its very simple.

 

if you google you will find the 3rd link down "How to Disable the Submit Button";

 

on that page you would find: onclick="this.disabled=true"

----------

 

so. to save you time, instead of

onClick="disableForm('theform');return true"

 

use

 

onclick="this.disabled=true"

Link to comment
Share on other sites

Thank-you very much for pointing that out to me Mr Obvious but I need to do a lot more than disable the button when clicked - ie. change the status of it so the user has some vague idea that something is happening.

 

I've decided to post this in here because I need to know if the $_POST variables are affected when changing the attributes to an element on a page.

Link to comment
Share on other sites

hehe, mr obvious ^^. fyi _POST vars are submitted by the browser, therefor it may be browser specific (unlikely).

 

Element names and values dont get changed? so there should be no problem.

 

if you want to make a "Submitting" message to appear use divs and hide the div using CSS until the person clicks submit, at which point disable the button and show the "Loading" message.

 

Good nickname for me though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.