Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery why .text hide automatically

I find it very weird to see that if i display an error on error div on form submit they just disappear straight away

my test code

<!DOCTYPE html>
<html>
<head>
    <title>TEST</title>
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<form method="post" id="fid" action="#">
    <input type="text"><div id="err"></div>
    <input type="submit" value="Submit" name="button" />
</form>


<script type="text/javascript">
    $(function(){
        $('#fid').submit(function(){
            $('#err').text('Hello World');
            //$('#err').html('Hello World');
        });
    });
</script>
</body>
</html>

I'm just displaying an error message regardless if user has left the field empty or not just to check once i get this successfully then i would go and implement the full functionality.

PLEASE NOTE: the error mess appear for less then a second and then disappear automaticlly

Regards

like image 320
Amjad Avatar asked Sep 25 '26 06:09

Amjad


1 Answers

e.preventDefault(); stop the form submit action

$(function(){
        $('#fid').click(function(e){
           e.preventDefault();
            $('#err').text('Hello World');
            //$('#err').html('Hello World');
        });
    });

If this method is called, the default action of the event will not be triggered

like image 78
Balachandran Avatar answered Sep 27 '26 19:09

Balachandran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!