zain zain - 3 months ago 10
jQuery Question

How to use JavaScript to validate text box with popup notification?

I'm using this JavaScript code to validate a text box, but when the alert popup appears and the user presses okay it returns to the page and the submit button is disabled so when the user clicks submit no action occurs, any ideas?

if (document.getElementById('Title').value == "") {
alert('Please fill mobile number');
$(document).ready(function () {
$("form").submit(function (e) {
e.preventDefault(); //prevent default form submit

});
});
}


this line is the problem:

e.preventDefault();


I need substitutes please

Answer
 $("form").submit(function (e) {
     e.preventDefault();  
     if (document.getElementById('Title').value == "") {
        alert('Please fill mobile number');
        return false;
     }
});

in your code, validation and form submission working on separate.