...

View Full Version : disable/grey out submit button if input field is empty



iccy
02-04-2007, 02:09 AM
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.



<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:)

chump2877
02-04-2007, 04:26 AM
<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>

FJbrian
02-04-2007, 07:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum