Check if input value is empty and display an alert

前端 未结 4 715
猫巷女王i
猫巷女王i 2020-12-24 14:15

How is it possible to display an alert with jQuery if I click the submit button and the value of the input field is empty?

         


        
4条回答
  •  天涯浪人
    2020-12-24 14:21

    Also you can try this, if you want to focus on same text after error.

    If you wants to show this error message in a paragraph then you can use this one:

     $(document).ready(function () {
        $("#submit").click(function () {
            if($('#selBooks').val() === '') {
                $("#Paragraph_id").text("Please select a book and then proceed.").show();
                $('#selBooks').focus();
                return false;
            }
        });
     });
    

提交回复
热议问题