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
Coulton
the 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.