Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Submit button disable and enable upon correct validation

    Hi, I am having a problem with my script used to disable my submit button. I want the button to disable upon correct submission of the form, and the button to be kept enabled if the required fields are not filled in. I have the following code at the moment (which only does the first if statement).

    Code:
    SCRIPT CODE: 
    
    <script type="text/javascript" >
    function validateForm()
    {
    
    var amount=document.forms["expenserecord"]["amount"].value;
    var picker=document.forms["expenserecord"]["picker"].value;
    var desc=document.forms["expenserecord"]["description"].value;
    
    if (amount==null || amount=="" || picker==null || picker=="" || desc==null || desc=="") {
      alert("All required fields must be filled out.");
      document.getElementById("sub").disabled = false;
      return false;
    }
     
    else {
     	document.getElementByID("sub").disabled = true;	
    }
    
    }
    
    </script>
    
    BUTTON CODE:
    
    <p><input type="submit" value="Submit" onClick="return validateForm()" id="sub"></p>

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Unless you are performing a submit to another document using as target a hidden iframe (which is subtle technique of uploading without changing the main document's session), the submit action will change the session anyway, thus any javascript change you could have done before is lost.

    You may, probably use a cookie (client or server side) to solve that problem. Or you may use AJAX to submit data, which will allow you to keep the session.

    http://en.wikipedia.org/wiki/Ajax_%28programming%29
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    Unless you are performing a submit to another document using as target a hidden iframe (which is subtle technique of uploading without changing the main document's session), the submit action will change the session anyway, thus any javascript change you could have done before is lost.

    You may, probably use a cookie (client or server side) to solve that problem. Or you may use AJAX to submit data, which will allow you to keep the session.

    http://en.wikipedia.org/wiki/Ajax_%28programming%29
    I solved the issue by changing the button to have an onChange() value referring to the script also. Thanks anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •