javascript - jQuery disable/enable submit button

Publicado el: 14 junio 2023
en el canal de: Code Samples
211
8

#short
#javascript
#html
#jquery
I have this HTML:
input type="text" name="textField" /
input type="submit" value="send" /

How can I do something like this:

When the text field is empty the submit should be disabled (disabled="disabled").
When something is typed in the text field to remove the disabled attribute.
If the text field becomes empty again(the text is deleted) the submit button should be disabled again.

I tried something like this:
$(document).ready(function(){
$('input[type="submit"]').attr('disabled','disabled');
$('input[type="text"]').change(function(){
if($(this).val != ''){
$('input[type="submit"]').removeAttr('disabled');
}
});
});

…but it doesn't work. Any ideas?


En esta página del sitio puede ver el video en línea javascript - jQuery disable/enable submit button de Duración hora minuto segunda en buena calidad , que subió el usuario Code Samples 14 junio 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 211 veces y le gustó 8 a los espectadores. Disfruta viendo!