Home > Article > Web Front-end > How to Enable/Disable a jQuery Submit Button Based on Text Field Input?
In a scenario where you require a submit button that's inactive when the corresponding text field is empty and becomes active once text is entered, the following steps provide a robust solution:
Disable the Submit Button Initially:
$(document).ready(function() { $(':input[type="submit"]').prop('disabled', true); });
Monitor Text Field Changes using keyup Event:
$('input[type="text"]').keyup(function() { // Check if the text field is not empty if($(this).val() != '') { // Enable the submit button $(':input[type="submit"]').prop('disabled', false); } else { // Disable the submit button $(':input[type="submit"]').prop('disabled', true); } });
The above is the detailed content of How to Enable/Disable a jQuery Submit Button Based on Text Field Input?. For more information, please follow other related articles on the PHP Chinese website!