Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Password change validation using jquery in Laravel

To implement password change validation using jQuery in Laravel, you can follow these steps. Here’s a basic example:

put below code in blade page

<form method="post" id="sample_form"
    class="form-horizontal" enctype="multipart/form-data"
    onsubmit="return check()">
    @csrf
    <div class="form-group" id="name_form">
        <label class="control-label">Name: </label>
        <input type="text" name="name"
            id="name" class="form-control" />
    </div>
    <!-- password show and hide open -->
    <div class="form-group" id="name_form">
        <label>Password</label>
        <div class="input-group" id="show_hide_password">
            <input class="form-control input-group-addon"
                type="password" name="password"
                id="password_user">
            <div class="input-group-addon">
                <a href=""><button
                        class="btn btn-light border"><i
                            class="fa fa-eye-slash"
                            aria-hidden="true"></i></button></a>
            </div>
        </div>
    </div>
    <!-- password show and hide close -->
    <!--cornfirm password show and hide open -->
    <div class="form-group" id="name_form">
        <label>Confirm Password</label>
        <div class="input-group">
            <input class="form-control" type="password"
                name="password" id="confirm_password">
        </div>
        <span id='message'></span>
    </div>
    <!-- cornfirm password show and hide close -->
    <input type="hidden" value="{{ Auth::user()->id }}"
        name="admin_id" id="admin_id" />
    <input type="hidden"
        value="{{ Auth::user()->email }}"
        name="admin_email" id="admin_email" />
    <!-- for account admin below value fo id and email will be null but when manager or user will store it it will get value by auth -->
    <input type="hidden"
        value="{{ Auth::user()->email }}" name="email">
    <input type="hidden" value="{{ date('d-m-y') }}"
        name="daymonth">
    <input type="hidden" value="null" name="user_id"
        id="user_id">
    <input type="hidden" value="null"
        name="user_email" id="user_email">
    <input type="hidden" value="" name="slugname">
    <input type="hidden" value="" name="slug_id">
</div>
<div class="form-group text-center">
<input type="hidden" name="action" id="action" />
<input type="hidden" name="hidden_id" id="hidden_id" />
<input type="submit" name="action_button"
    id="action_button"
    class="btn btn-warning float-center" value="Add" />
</div>
</form>

put below code in script tag

 <script>
    $('#confirm_password').on('keyup', function() {
        if ($(this).val() == $('#password_user').val()) {
            $('#message').html('Password matched').css('color', 'green');
        } else $('#message').html('Password not matching').css('color', 'red');
    });
    </script>

Next go to update function and put below code

$('#sample_form').on('submit', function(event) {
    event.preventDefault();
    // Check if passwords match
    if ($('#confirm_password').val() != $('#password_user').val()) {
        // Display an error message or take appropriate action
        $('#message').html('Password not matching').css('color', 'red');
        return;
    }
    // data add working on submit button
    // update button wotking for updata data
    if ($('#action').val() == "Update") {
        console.log('update button pe click ho rha hai');
        $.ajax({
            url: "{{ url('viewprofile/update') }}",
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            dataType: "json",
            headers: {
                "Authorization": "Bearer " + localStorage.getItem('a_u_a_b_t')
            },
            // message alert open
            success: function(data) {
                var html = '';
                if (data.success) {
                    html = '<div class="alert alert-success">' + data.message +
                        '</div>';
                    $('#form_result').html(html);
                    setTimeout(function() {
                        $('#user_formModal').modal('hide');
                        location.reload(true);
                    }, 2000);
                } else {
                    html = '<div class="alert alert-danger">' + data.message +
                        '</div>';
                    $('#form_result').html(html);
                }
                // adding alert messages for success and exist data validation close
            },
            // message alert close
            error: function(data) {
                console.log('Error:', data);
                //    this function for hide with id #formModel
                console.log('update function kamm nahi kr rha hai');
            }
        });
    }
});

Now update working successfully.

Hi I am Amit Kumar Thakur Experienced as s Software Developer with a demonstrated history of working in the information technology and services industry. Skilled in HTML, CSS, Bootstrap4, PHP, Laravel-9 , REST API,FB API,Google API, Youtube Api, Bitbucket,Github,Linux and jQuery. Strong engineering professional focused in Computer/Information Technology Administration and Management. Currently my profile is to Software Developer, analyze the requirement, creating frame for web application, coding and maintenance.

Related Posts

How to Crawl any website Meta Title and Meta Description in Laravel ?

1st step install below package. Next to create Controller First go to route and put below code Next go to controller and put below code Next go…

SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: insert into `oauth_clients` (`user_id`, `name`, `secret`

In this tutorial i’m going to solve the error SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: insert into oauth_clients (user_id, name, secret Error :-…

Top 20 Laravel Interview Question in 2024

In this tutorial im going share interview experience For laravel developer. A list of top frequently asked Laravel Interview Questions and answers are given below. Q #1) What is…

How to Get Google Analytics API key ?

In this tutorial we’re going to share how to get the google Analytics API key. I have shared in very easy way. First go enable Google analytics…

Youtube Subscriber Count in ReactJs

In this tutorial i’m going to learn how to count YouTube Subsribers count, views count as well, as define below. In order to install your app, first…

How to Disable Laravel’s Eloquent timestamps in laravel ?

In this tutorial we’re going to share how to disable the automatic created_at and updated_at timestamps in Laravel’s Eloquent models, along with explanations of different scenarios: 1st…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x