locked
JQuery - when user keyup clear div error message... RRS feed

  • Question

  • User-507786106 posted

    How do I clear error message when the user keyup or type a character into the textbox?

    how to clear the div when a character is typed into textbox?

    Thursday, April 11, 2019 3:08 PM

Answers

  • User839733648 posted

    Hi slimbunny,

    You could just use .siblings() and .fadeOut() to make the error_mesage div to hide.

    Here is my testing sample.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
        <script>
            $(function () {
                $(".validate").keyup(function (e) {
                    $(this).siblings('.validator').fadeOut();
                });
            })
        </script>
    </head>
    <body>
        <div>
            <input id="first_name" class="validate form-control" type="text" name="first_name" placeholder="First Name" />
            <div id="error_first_name" class="validator err alert alert-danger">
                The first name may should not be empty.
            </div>
        </div>
    </body>
    </html>

    result:

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 16, 2019 6:27 AM

All replies

  • User475983607 posted

    How do I clear error message when the user keyup or type a character into the textbox?

    how to clear the div when a character is typed into textbox?

    Pretty simple.

    $('selector').keyup(function(){
    	$('errorMessageSelector').html('');
    });

    Or use $('errorMessageSelector').text('');

    You can find the selector using dev tool (F12).  Right click on the element in the elements view -> Copy -> Copy selector.  then paste the selector in you script.

    I strongly recommend that you learn jQuery from the jQuery docs.

    Thursday, April 11, 2019 5:56 PM
  • User839733648 posted

    Hi slimbunny,

    You could just use .siblings() and .fadeOut() to make the error_mesage div to hide.

    Here is my testing sample.

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
        <script>
            $(function () {
                $(".validate").keyup(function (e) {
                    $(this).siblings('.validator').fadeOut();
                });
            })
        </script>
    </head>
    <body>
        <div>
            <input id="first_name" class="validate form-control" type="text" name="first_name" placeholder="First Name" />
            <div id="error_first_name" class="validator err alert alert-danger">
                The first name may should not be empty.
            </div>
        </div>
    </body>
    </html>

    result:

    Best Regards,

    Jenifer

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 16, 2019 6:27 AM