The automated Login Pop Up button appears on its own and does not immediately redirect to the login form

Hey guys, I'm struggling with modifying the jquery and html to ensure that when the login button is clicked, the login form pops up instead of displaying another login button. Another issue I am facing is that the login button seems to pop up automatically upon loading.

Check out my code on jsFiddle

I'm a beginner in Jquery and despite trying to solve this problem, I haven't had any luck. If anyone has a solution for me, please share the code changes or update the jsfiddle link provided. Thank you!

Here's the HTML code snippet:

<div class="container">
    <a id="modal_trigger" href="#modal" class="btn">Login</a>
    <div id="modal" class="popupContainer" style="display:none;">
        <header class="popupHeader">
            <span class="header_title">Login</span>
            <span class="modal_close"><i class="fa fa-times"></i></span>
        </header>
        <section class="popupBody">
            <!-- Social Login -->
            <div class="social_login">
                <div class="action_btns">
                    <div class="one_half"><a href="#" id="login_form" class="btn">Login</a></div>
                </div>
            </div>
            <!-- Username & Password Login form -->
            <div class="user_login">
                <form>
                    <label>Email / Username</label>
                    <input type="text" />
                    <br />

                    <label>Password</label>
                    <input type="password" />
                    <br />

                    <div class="checkbox">
                        <input id="remember" type="checkbox" />
                        <label for="remember">Remember me on this computer</label>
                    </div>
                </form>
                <a href="#" class="forgot_password">Forgot password?</a>
            </div>
            <!-- Register Form -->
            <div class="user_register">
                <form>
                    <label>Full Name</label>
                    <input type="text" />
                    <br />

                    <label>Email Address</label>
                    <input type="email" />
                    <br />

                    <label>Password</label>
                    <input type="password" />
                    <br />

                    <div class="checkbox">
                        <input id="send_updates" type="checkbox" />
                        <label for="send_updates">Send me occasional email updates</label>
                    </div>

                    <div class="action_btns">
                        <div class="one_half"><a href="#" class="btn back_btn"><i class="fa fa-angle-double-left"></i> Back</a></div>
                        <div class="one_half last"><a href="#" class="btn btn_red">Register</a></div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>

And here's the relevant JQUERY code:

(function ($) {
    $.fn.extend({
        leanModal: function (options) {
            var defaults = {
                top: 100,
                overlay: 0.5,
                closeButton: null
            };
            var overlay = $("<div id='lean_overlay'></div>");
            $("body").append(overlay);
            options = $.extend(defaults, options);
            return this.each(function () {
                var o = options;
                var modal_id = $(this).attr("href");

                function showModal() {
                    $("#lean_overlay").click(function () {
                        close_modal(modal_id)
                    });
                    $(o.closeButton).click(function () {
                        close_modal(modal_id)
                    });

                    var modal_height = $(modal_id).outerHeight();
                    var modal_width = $(modal_id).outerWidth();

                    $("#lean_overlay").css({
                        "display": "block",
                        opacity: 0
                    });

                    $("#lean_overlay").fadeTo(200, o.overlay);

                    $(modal_id).css({
                        "display": "block",
                        "position": "fixed",
                        "opacity": 0,
                        "z-index": 11000,
                        "left": 50 + "%",
                        "margin-left": -(modal_width / 2) + "px",
                        "top": o.top + "px"
                    });

                    $(modal_id).fadeTo(200, 1);
                };

                $(document).ready(function () {
                    showModal();
                });

                $(this).click(function (e) {
                    showModal();
                    e.preventDefault()
                })
            });

            function close_modal(modal_id) {
                $("#lean_overlay").fadeOut(200);
                $(modal_id).css({
                    "display": "none"
                })
            }
        }
    })
})(jQuery);



$("#modal_trigger").leanModal({top : 200, overlay : 0.6, closeButton: ".modal_close" });

    $(function(){
        // Showing User Login Form
        $("#login_form").click(function(){
            $(".social_login").hide();
            $(".user_login").show();
            return false;
        });

    })

CSS styles being used are as follows:

@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,700italic,400italic);

body {font-family: 'Source Sans Pro', sans-serif; font-size: 14px; color: #666;}

#lean_overlay {
    position: fixed;
    z-index:100;
    top: 0px;
    left: 0px;
    height:100%;
    width:100%;
    background: #000;
    display: none;
}

.popupContainer{
    position:absolute;
    width:330px;
    height: auto;
    left:45%;
    top:80px;
    background: #FFF;
}

#modal_trigger {margin:100px auto; width:100px; display:block;}

.btn {padding:10px 20px; background: #F4F4F2;}
.btn_red {background: #ED6347; color: #FFF;}

.btn:hover {background: #E4E4E2;}
.btn_red:hover {background: #C12B05;}

a.btn {color:#666; text-align: center; text-decoration: none;}
a.btn_red {color: #FFF;}

.one_half {width:50%; display: block; float:left;}
.one_half.last {width:45%; margin-left:5%;}

/* Popup Styles*/
.popupHeader {font-size:16px; text-transform: uppercase;}
.popupHeader {background:#F4F4F2; position:relative; padding:10px 20px; border-bottom:1px solid #DDD; font-weight:bold;}
.popupHeader .modal_close {position: absolute; right: 0; top:0; padding:10px 15px; background:#E4E4E2; cursor: pointer; color:#aaa; font-size:16px;}

.popupBody {padding:20px;}

/* Other CSS styles... */

Answer №1

Eliminated a function (as well as implementing minor adjustments, referenced in DEMO):

$(document).ready(function () {
     displayModal();
});

DEMO: interactive demo

Answer №2

Ensuring proper initial display settings is crucial, as demonstrated below:

.social_login {display: none;}
.user_login {display: block;}

It's important to thoroughly review all your code for any lingering issues.

DEMO: https://jsfiddle.net/lmgonzalves/1s3gycd8/1/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The collapsed form-control is adjusting its attributes while resizing

Having trouble with a website design featuring a collapsed window and menu items, but the search bar is not displaying correctly? In image 3, you can see that the style of the search bar changes when the width exceeds a certain limit. I've tried vario ...

Are there any functions that work with an array of objects?

Is there a way to use includes function to check if an object is inside the array, as shown below: arr=[{name:'Dan',id:2}] When trying to check with includes like this: arr.includes({name:'Dan',id:2}) The result returned is false. I ...

Is there a way to transfer a value set from one tpl file to another tpl file in cscart using smarty template engine?

I am trying to retrieve the value of a variable set using an input tag from one tpl file. Here is the input tag in A.tpl file: <input type="checkbox" class="checkbox" name="payment_data[processor_params][enable_addbillcard]" id="optional_enable_addbil ...

Effortlessly alternate between dual-column and single-column layouts using CSS

Creating a basic two column layout with fixed widths is my current project. <div id='box'> <div id='ontop'>Ontop</div> <div id='column1'>Column1</div> <div id='column2'&g ...

Horizontal Scroll HTML

Currently in the process of building a website for my father, everything is going smoothly. I followed a helpful Stackoverflow tutorial to create a specific webpage that I now want to customize with a hyperlink and make it scroll horizontally: Sliding divs ...

What is the best way to design an element in HTML/CSS with a curved semicircle border at the top?

I'm looking to design an HTML/CSS element that features a semicircle at the top-middle with a border. Inside this semicircle, I want to place a smaller circle containing a single character (similar to the X in the provided image). Additionally, there ...

Why won't the props pass down to the child component?

I am facing an issue while trying to pass two values as props from a React component "App" to its child "Todo". The values being passed are "title" and "completed" from a json placeholder API. The JSON object is correct and has been verified. The problem ...

What is the best way to prevent the deletion of a specific value in ChipInput (material-ui-chip-input)?

Incorporating the chip input feature from material-ui-chip-input into my project has been great for entering emails. However, I am faced with a challenge - I need to disable the ability to delete specific values. Specifically, when populating the input f ...

Display error messages upon submitting the form

I am currently working on an Angular 6 Form with validation. My main goal is to display error messages only after the form has been submitted. It is crucial that these messages remain constant while the user types in the input field. For instance, if a use ...

There was an error in Angular at core.js:6150 stating that the object is not iterable due to a

I am facing an issue in displaying the First Name of a user in an HTML file getFirstName(id: any){ this.users = this.afs.collection('users', ref => ref.where("uid", "==", id)).valueChanges(); this.users.subscribe(users => { ...

Accessing and manipulating a scope variable in Angular from an external source

Can you update a $scope variable in a controller from an external source? For instance, suppose we have the following controller: app.controller('citySelectCtrl', ['$scope',function($scope){ }]); And there is a function in the globa ...

What is the best way to integrate bootstrap modal forms using django-crispy-forms without causing a page refresh?

Recently, I've been working on setting up a form within a bootstrap modal using django-crispy forms and class-based views. While looking into incorporating Ajax functionality, I found several examples that weren't entirely clear to me. I tested ...

Typescript: Ways to fix the error 'rxjs/Rx does not have any exported member 'SubscriptionLike'

I'm attempting to replicate the steps outlined in this tutorial found here https://www.youtube.com/watch?v=gxCu5TEmxXE. However, upon running tsc -p, I encounter an error. Is there a specific import that I am missing? ERROR: node_modules/@angular/co ...

dilemma with jquery slideshow

I have a unique challenge where I want to display different images for each month of the year. My goal is to create a slide show that will showcase the images related to the selected month on top of the page. However, when I click on a specific month, I en ...

ng-view is the culprit behind the website's fatal error

Encountering a "RangeError: Maximum call stack size exceeded" in the console while trying to recreate a basic routing example from w3schools. The crash seems to be linked to <div ng-view></div> in index.html. Despite making minimal changes from ...

Redirecting in AngularJS after a successful login操作

Is there a way to redirect users back to the original page after they login? For example, if a user is on a post like www.example.com/post/435 and needs to log in to "like/comment" on the post, how can I automatically redirect them back to that specific po ...

Clicking on a radio button will update the text within a span

Can jQuery AJAX be used for this task? I am looking to update the content of a <span> when a radio button is clicked. <input class="unitSelectInches" type="radio" name="units" value="inches" />Inches <input class="unitSelectCenti" type="ra ...

Does Less undergo a compilation process in a single pass?

Does Less execute a single pass on the files, or does it perform multiple passes? I am particularly worried about what will happen if I include another file that redefines variables and mixins. Will the generated output use the original values, or will it ...

What is the best way to serialize form data while also including a child collection?

Currently, I have a webpage within my web application where I am in the process of creating a Person object using an AJAX POST request. The required JSON format that needs to be sent to the API endpoint is as follows: { "categoryId": "string", "na ...

Tips for deactivating a single edit button

Is there a way to make it so that when I click on a checkbox, only that specific todo's edit button is disabled? Currently, clicking on a checkbox disables all edit buttons in the todo list. Any suggestions? class App extends Component { state ...