How occur submit event in html page and how to handle in JQ?

2 votes
Ethan Karla asked 28-Jul-2021 in Web Application by Ethan Karla

How occur submit event in html page and how to handle in JQ?

1 Answer

2 votes
Ravi Vishwakarma answered 03-Aug-2021 by Ravi Vishwakarma

The jquery submit event is then occure, When we send data from form tag then submit event calls.

<!doctype html>

<html lang='en'>
    <!-- Required meta tags -->
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
    <script src=''></script>
    <!-- Bootstrap CSS -->
    <link href='' rel='stylesheet' integrity='sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC' crossorigin='anonymous'>
    <title>Submit Event demo</title>
    <div class='container'>
        <h1 class='text-center mt-5'>Login to Database</h1>
        <form class='m-2' action='' method='get'>
            <div class='form-group m-2'>
                <label class=''>Username </label>
                <input type='text' class='form-control' placeholder='Enter your username'name='email' />
            <div class='form-group m-2'>
                <label class=''>Password </label>
                <input type='password' class='form-control' placeholder='Enter your password' name='pass'/>
            <div class='form-group form-check m-2' >
                <label class='form-check-label'> <input type='checkbox' class='form-check-input' />Remember me</label>
            <input type='submit' class='btn btn-primary m-2' value='Submit Data' />
        <p class='alert m-3'></p>
        $(document).ready(function () {
            $('form').submit(function (event){
                if ( $(':password').val() === '1234' ) {
                    $('p').text('Submitted Successfully. ' + $(':text').val() + ' and ' + $(':password').val()).addClass('alert-success');
                    $('p').text('Not valid! '+ $(':text').val() + ' and ' + $(':password').val()).addClass('alert-danger');
    <script src='' integrity='sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo' crossorigin='anonymous'></script>
    <script src='' integrity='sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1' crossorigin='anonymous'></script>
    <script src='' integrity='sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM' crossorigin='anonymous'></script>


How occur submit event in html page and how to handle in JQ?