Enable button only if all fields are filled out?
I have a form that I want to only let the button be active if the user has filled out all the info. I am new to javascript and would like a little help. Thanks!
Here's my script:
<script type="text/javascript">
function enableDisableSend(oFld){
name = oFld.form.summary.value;
question = oFld.form.question.value;
if (question == '' OR name == '') {
oFld.form.write.disabled = TRUE;
document.getElementById("write").className = 'comment_popup_button_disabled';
} else {
oFld.form.write.disabled = FALSE;
document.getElementById("write").className = 'comment_popup_button_active';
}
}
</script>
<body onload="enableDisableSend(document.login.comments)">
<form name="login" method="post" id="login">
<input type='text'
name='summary'
id='summary'
开发者_运维技巧 onFocus="clearText(this)"
onBlur="clearText(this)"
class="support_popup_form"
value="" onkeyup="enableDisableSend(this)"
onblur="enableDisableSend(this)"
onpaste="setTimeout('enableDisableSend(document.'+this.form.name+'.'+this.name+')', 10)"
/>
<textarea name="question"
id='question'
rows="10"
class="support_popup_form"
onFocus="clearText(this)"
onBlur="clearText(this)"
style="min-height: 164px; max-height: 164px;"
onkeyup="enableDisableSend(this)"
onblur="enableDisableSend(this)"
onpaste="setTimeout('enableDisableSend(document.'+this.form.name+'.'+this.name+')', 10)"
maxlength="120">
</textarea>
<input type='submit'
value='Ask Question'
class="comment_popup_button_disabled"
id="write"
name="write"/></div>
</form>
However, nothing happens when you change the field. Can you please help me modify my code to make it work or guide me in the right direction?
Thanks
Coultonthe syntax for an OR condition is ||
if (question == '' || name == '') {
you have no element with the name or id comments
Javascript is case sensitive.
You need to write true
and false
.
精彩评论