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 Coder
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation disable/grey out submit button if input field is empty

    Hi'

    I am looking for a function which will let me have the form submit button disabled if the username field is empty. If someone could give me a quick function and how to implement it into a form that would be really great. I already have a onsubmit event to my form like below.

    Code:
    <form class="whitesmall1" action="/forums/login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
    <input type="text" class="whitesmall1" style="background-color:#223E76" name="vb_login_username" id="navbar_username" size="20" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" />
    Thanks in advance

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Code:
    <form name="form1" class="whitesmall1" action="/forums/login.php?do=login" method="post" onsubmit="md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0)">
        <input type="text" class="whitesmall1" style="background-color:#223E76;color:white" name="vb_login_username" id="navbar_username" size="20" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" onkeyup="blah(document.form1);" />
        <input type="submit" name="submitBut" value="Submit" disabled="disabled" />
    </form>
    
    <script type="text/javascript">
    
    function blah(form_obj)
    {
        if (form_obj.vb_login_username.value != 'User Name' && form_obj.vb_login_username.value != '')
            form_obj.submitBut.disabled = false;
        else
            form_obj.submitBut.disabled = true;
    }
    
    </script>
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    drawing a blank on the word it's not "onclick" but....when ya click away from an object/item

    "write" the button when that happens


  •  

    Posting Permissions

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