Interactive online courses HTML Academy
2026-03-09 14:06 Diff

We added a conditional statement to our script, and now, if a new comment is longer than 142 characters, an error message will appear. However, this will not prevent us from submitting the form and posting a comment that is too long. To fix this, you need to not only add a class to the form, but also to lock the submission button. If the button is locked, the form cannot be submitted.

You can lock and unlock the button in JavaScript by assigning Boolean values to the disabled property for this button. If the true value is assigned, then the button is locked, whereas if it is assigned false, then the button is unlocked.

let button = document.querySelector('button'); // Locks the button button.disabled = true; // Unlocks the button button.disabled = false;

The button with the submit-button class is responsible for submitting a new comment on our website. Find it and save it to the variable. After that add the conditional statement: if the comment is too long, the submit button must be locked. Check how the form works now.