Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  195] [ 7]  / answers: 1 / hits: 21872  / 11 Years ago, wed, november 6, 2013, 12:00:00

I have this code that disable the button when the text is empty, but I have a textarea html code. How can I include this that when the text and textarea are both empty the button will be disabled and when both are filled it enables. I tried the code below and it works on text only. Any ideas?





$(document).ready(function() {
$('input[type=submit]').attr('disabled', true);

$('input[type=text]').on('keyup',function() {
if($(this).val() != '') {
$('input[type=submit]').attr('disabled', false);
} else {
$('input[type=submit]').attr('disabled', true);
}
});
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>

<input type=text name=textField />
<textarea rows=4 cols=30 ></textarea>
<input type=submit value=next />




More From » jquery

 Answers
4

You miss the textarea selector in jQuery





$(document).ready(function() {
$('input[type=submit]').attr('disabled', true);

$('input[type=text],textarea').on('keyup',function() {
var textarea_value = $(#texta).val();
var text_value = $('input[name=textField]').val();

if(textarea_value != '' && text_value != '') {
$('input[type=submit]').attr('disabled', false);
} else {
$('input[type=submit]').attr('disabled', true);
}
});
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>

<input type=text name=textField /><br>
<textarea rows=4 cols=30 id=texta></textarea><br>
<input type=submit value=next />




[#74481] Tuesday, November 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brandensebastiand

Total Points: 323
Total Questions: 115
Total Answers: 106

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;