SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disable Submit button with Validate form

    I've been working on this for awhile now and can't seem to figure it out. I'd like to include a disable submit button into the following VALIDATION code...

    I've used
    onclick="this.disabled=true;"

    however the submit button remains disable if the form returns invalid.

    this is a huge chunk of code, sorry

    PHP Code:

    var new_fieldname ""
    function check(form,x)
    {
        var 
    set_up_var ""
        
    var message ""
        
    var more_message ""
        
    var showmsg "no"
        
    if (set_up_var == "")
        {
            
    1
            
    for (var 0<= xi++)
                {
                     var 
    messenger form.elements[i].name
                    messenger 
    messenger.substring(02)
                    var 
    fieldname form.elements[i].name
                    fieldname 
    fieldname.substring(2)

                        {
                            if (
    messenger == "r_")
                                {
                                    
    more_message r_check(form,x,fieldname,i)
                                }
                            else if (
    messenger == "i_")
                                {
                                    
    more_message i_check(form,x,fieldname,i)
                                }
                            else if (
    messenger == "d_")
                                    {
                                        
    more_message d_check(form,x,fieldname,i)
                                    }
                            else if (
    messenger == "e_")
                                    {
                                        
    more_message e_check(form,x,fieldname,i)
                                    }            
                                 if (
    more_message != "")
                {
                                        if (
    message == "")
                                            {
                                                
    message more_message
                                                more_message
    =""
                                            
    }
                                        else
                                            {
                        
    message message "\n" more_message
                                                more_message
    =""
                                            
    }
                }
                                                
                            if (
    message "")
                                    {
                                            
    showmsg "yes"
                                    
    }                                                    
                            }    
                    }
                
            if (
    showmsg == "yes")
                {
                    
    alert("PLEASE COMPLETE OR CORRECT THE FOLLOWING FORM FIELD(s)\n\n" message )
                }
            else
                {
                    
    form.submit()
                }                
            
            }
        else
            {
                
    alert ("")
            }
    }    

    function 
    r_check(form,x,fieldname,i)
        {
            var 
    msg_addition ""
            
    new_fieldname fieldname
            
    for (var 0<= xy++)
                {

                    if ((
    form.elements[y].type == "radio" || form.elements[y].type == "checkbox") && form.elements[y].name == new_fieldname && form.elements[y].checked == true)
                        {
                                
    msg_addition ""
                                
    break
                        }
                    else if ((
    form.elements[y].type == "radio" || form.elements[y].type == "checkbox") && form.elements[y].name == new_fieldname && form.elements[y].checked == false)
                        {
                            
    msg_addition form.elements[i].value
                        
    }

                else if (
    form.elements[y].type == "select-one")
                                {
                                    var 
    form.elements[y].selectedIndex
                                    
    if (form.elements[y].name == fieldname && form.elements[y].options[l].value != "")
                                        {
                                            
    msg_addition ""
                                            
    break
                                        }
                                    else if (
    form.elements[y].name == fieldname && form.elements[y].options[l].value == "")
                                        {
                                            
                                            
    msg_addition form.elements[i].value

                                        
    }
                                    }
             else if (
    form.elements[y].name == fieldname && form.elements[y].value == "" && form.elements[y].type != "radio" && form.elements[y].type != "checkbox" && form.elements[y].type != "select-one")
                                {
                                    
                                    
    msg_addition form.elements[i].value
                                    
    break
                                }
                    else if (
    form.elements[y].name == fieldname && form.elements[y].value != "" && form.elements[y].type != "radio" && form.elements[y].type != "checkbox" && form.elements[y].type != "select-one")
                                {
                                    
    msg_addition ""

                                
    }    

                    }
                return(
    msg_addition)
            }
                
                
    function 
    i_check(form,x,fieldname,i)
        {
            for (var 
    0<= xy++)
                {
                    if (
    form.elements[y].name == fieldname)
                    break
                }                        
        
        var 
    msg_addition ""
        
    var decimal ""
        
    inputStr form.elements[y].value.toString()
        
        if (
    inputStr == "")
            {
                
    //msg_addition = form.elements[i].value
            
    }
        else
            {
                for (var 
    0inputStr.lengthc++)
                    {
                        var 
    oneChar inputStr.charAt(c)
                        if (
    == && oneChar == "-" || oneChar == "."  && decimal == "")
                                {
                                    if (
    oneChar == ".")
                                        {
                                            
    decimal "yes"
                                        
    }
                                    continue
                                    
                                }
                                    if (
    oneChar "0" || oneChar "9")
                                        {
                                            
    msg_addition form.elements[i].value
                                        
    }
                    }
            }
            return(
    msg_addition)
        }    
        
        function 
    e_check(form,x,fieldname,i)
        {
            for (var 
    0<= xy++)
                {
                    if (
    form.elements[y].name == fieldname)
                    break
                }                        
            
        var 
    msg_addition ""
        
    period ".";

                    
                    if (
    form.elements[y].value == "" || form.elements[y].value.indexOf ('@'0) < 3)
                            
    error 1;
                                                                                            
                                                                    else
                      {
                           
    test form.elements[y].value.indexOf('.'form.elements[y].value.indexOf ('@'0))
                                             if (
    test != -1)
                                                                                        {
                                                                                            
    error 0;
                                                                                        }
                                                                                    else
                                                                                    {
                                 
    error=1;
                                                                                    }
                      }
                    if (
    error == 1)
                                                                        {
                                   
    msg_addition form.elements[i].value
                                                                        
    }
                    else
                     {
                                             
    new_length form.elements[y].value.length test
                 
    if (new_length == || new_length == || (new_length >= && form.elements[y].value.indexOf ('.', (test+1)) != -1))
                                                                                            {
                                                                                                
    msg_addition ""
                                                                                            
    }
                                                                                        else
                                                                                                
    msg_addition form.elements[i].value;
                                                                        }
        return(
    msg_addition)
        }    

        function 
    d_check(form,x,fieldname,i)
     {
            for (var 
    0<= xy++)
                {
                    if (
    form.elements[y].name == fieldname)
                    break
                }        
                
            var 
    msg_addition ""    
            
    var sDate form.elements[y].value
            
    var int_or_not isInteger(form.elements[y].value)
            

            if (
    form.elements[y].value != "") {
            
            if (
    int_or_not == "true")
                {
                    if ((!(
    form.elements[y].value.length >= 6)) || (!(form.elements[y].value.length <= 8)))
               {
                
    msg_addition form.elements[i].value
               
    }
              else
               {
                         var 
    SlashlPos form.elements[y].value.indexOf("/",0)
                            if (
    SlashlPos && SlashlPos <= 2)
                                {
                                    if (
    SlashlPos == 1)
                                        {
                                            if (
    form.elements[y].value.charAt(0) < || form.elements[y].value.charAt(0) > 9)
                                                {
                                                    
    msg_addition form.elements[i].value
                                                
    }
                                            else
                                                {
                                                    if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 8) && ((form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/")))
                                                        { 
                                                            
    msg_addition form.elements[i].value
                                                        
    }
                                                    else if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 8) && ((form.elements[y].value.charAt(2) >= && form.elements[y].value.charAt(3) > 1) || (form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/"))))
                                                        { 
                                                            
    msg_addition form.elements[i].value "hi"
                                                        
    }
                                                    else if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 8) && (((form.elements[y].value.charAt(2) > && form.elements[y].value.charAt(3) != "/") || (((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/")) && ((form.elements[y].value.length == || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
                                                        {
                                                            
    msg_addition form.elements[i].value
                                                        
    }
                                                    else
                                                        {
                                                            if ((
    form.elements[y].value.charAt(0) == && ((form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/") || (form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/")))))
                                                                { 
                                                                    
    msg_addition form.elements[i].value
                                                                
    }
                                                            else if (
    form.elements[y].value.charAt(0) == && ((form.elements[y].value.charAt(2) > && form.elements[y].value.charAt(3) != "/") || (((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/") && ((form.elements[y].value.length == || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
                                                                { 
                                                                    
    msg_addition form.elements[i].value
                                                                
    }
                                                            else
                                                                {
                                                                    if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 9) && ((form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(3) == "/" && form.elements[y].value.length >= 7) || (form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(2) == "/")))
                                                                        { 
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                    else if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 9) && ((form.elements[y].value.charAt(2) >= && form.elements[y].value.charAt(3) > 0) || (form.elements[y].value.charAt(2) == && form.elements[y].value.charAt(3) == 0) || (form.elements[y].value.charAt(1) == "/" && (form.elements[y].value.charAt(3) != "/" && form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/"))))
                                                                        { 
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                    else if ((
    form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == || form.elements[y].value.charAt(0) == 9) && (((form.elements[y].value.charAt(2) > && form.elements[y].value.charAt(3) != "/") || ((form.elements[y].value.charAt(1) == "/" && form.elements[y].value.charAt(4) == "/") && ((form.elements[y].value.length == || form.elements[y].value.length == 8)))) || form.elements[y].value.charAt(5) == "/"))
                                                                        {
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                }
                                                        }
                                                }
                                        }
                                    else
                                        {
                                            if (
    form.elements[y].value.charAt(0) > || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) > 2) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 0))
                                                {
                                                    
    msg_addition form.elements[i].value
                                                
    }
                                            else
                                                {
                                                    if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/"))))
                                                        {
                                                            
    msg_addition form.elements[i].value        
                                                        
    }
                                                    else if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) >= && form.elements[y].value.charAt(4) > 1) || (form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == 0) || form.elements[y].value.length 7))
                                                        {
                                                            
    msg_addition form.elements[i].value
                                                        
    }
                                                    else if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 3) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 5) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 7) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 8) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 0) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 2)) && ((form.elements[y].value.charAt(3) > && form.elements[y].value.charAt(4) != "/")    || ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == ||
     
    form.elements[y].value.length == 8)))))
                                                        {
                                                            
    msg_addition form.elements[i].value
                                                        
    }
                                                    else
                                                        {
                                                            if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 2) && ((form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == 0)) || form.elements[y].value.length 7) || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/")))
                                                                {
                                                                    
    msg_addition form.elements[i].value
                                                                
    }
                                                            else if ((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 2) && ((form.elements[y].value.charAt(3) > && form.elements[y].value.charAt(4) != "/") || ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == || form.elements[y].value.length == 8)))))
                                                                {
                                                                    
    msg_addition form.elements[i].value
                                                                
    }
                                                            else
                                                                {            
                                                                    if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(3) == "/") || (form.elements[y].value.charAt(2) == "/" && (form.elements[y].value.charAt(4) != "/" && form.elements[y].value.charAt(5) != "/" && form.elements[y].value.charAt(6) != "/" && form.elements[y].value.charAt(7) != "/"))))
                                                                        {
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                    else if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) >= && form.elements[y].value.charAt(4) > 0) || (form.elements[y].value.charAt(3) == && form.elements[y].value.charAt(4) == 0) || form.elements[y].value.length 7))
                                                                        {
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                    else if (((
    form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 4) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 6) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 9) || (form.elements[y].value.charAt(0) == && form.elements[y].value.charAt(1) == 1)) && ((form.elements[y].value.charAt(3) > && form.elements[y].value.charAt(4) != "/") || ((form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(5) == "/" && form.elements[y].value.length == || form.elements[y].value.charAt(6) == "/") || (form.elements[y].value.charAt(2) == "/" && form.elements[y].value.charAt(4) == "/" && (form.elements[y].value.length == || form.elements[y].value.length == 8)))))
                                                                        {
                                                                            
    msg_addition form.elements[i].value
                                                                        
    }
                                                                }
                                                        }        
                                                }
                                        }
                                }
                else
                                {
                                    
    msg_addition form.elements[i].value
                                
    }
                        }
                }
            else
                {
                    
    msg_addition form.elements[i].value
                
    }
            return(
    msg_addition)
        }
        

        return(
    msg_addition)
        }
        
        function 
    isInteger(sDate)
        {
            var 
    new_msg "true"
            
    inputStr sDate.toString()
            for (var 
    0inputStr.lengthi++)
                {
                var 
    oneChar inputStr.charAt(i)            
                if ((
    oneChar "0" || oneChar "9") && oneChar != "/")
                        {
                            
    new_msg "false"
                        
    }
                }
            return (
    new_msg)
        }
        
        function 
    asc(each_char)
            {
            var 
    0
                
    var char_str charSetStr()
                for (
    0char_str.lengthi++)
                    {
                        if (
    each_char == char_str.substring(ii+1))
                            {
                                break
                            }
                    }
                return 
    32
            
    }
            
            function 
    charSetStr()
                {
                    var 
    str
                 str 
    ' !"#$%&' "'" '()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
                    
    return str
                


    thanks for any help

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Put this in the head of your document:

    Code:
    <script type="text/javascript">
    function stopDblClick()
    {
         onsubmit = null
    }
    </script>
    and this in your form:

    <form onsubmit="stopDblClick();">

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    canada
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the feedback so far, my question is: how do I incorporate the
    <form onsubmit="stopDblClick();">

    while preserving the

    <form onSubmit="return checksubmit()">

    that is already present?

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Add this to the checksubmit() function. Make it the first lines:

    Code:
    var storeEvent = onsubmit;
    onsubmit = null;
    Where you return false in your checksubmit() function (because validation fails) put this line right before it:

    Code:
    onsubmit = storeEvent;


Bookmarks

Posting Permissions

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