1

I have this Login/Signup link on which when user clicks,it pops up a login window.

enter image description here

Now when a user has to login he can simply login through this pop window.

This is the code for the login/signup link

<a id="modal_trigger" href="#modal" style="margin-top:6px; margin-right:14px">Login|Signup</a>

Given is the Jquery for the pop up window

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

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

    // Calling Register Form
    $("#register_form").click(function(){
        $(".social_login").hide();
        $(".user_register").show();
        $(".header_title").text('Register');
        return false;
    });

    // Going back to Social Forms
    $(".back_btn").click(function(){
        $(".user_login").hide();
        $(".user_register").hide();
        $(".social_login").show();
        $(".header_title").text('Login');
        return false;
    });

})

Note : i have tried this document.getElementById('modal_trigger').click(); and possibly this might be a duplication of this question How do I programmatically click a link with javascript? but i don't seem to get my answer.

Question : Pop up window comes only comes up when user clicks the 'Login/Signup' hyperlink.How do i make this pop up to come programmingly ?

Update:

$( document ).ready(function() {
    $("#modal_trigger")[0].click();
});



$( document ).ready(function() {
    $(function() {
        $("#modal_trigger").leanModal({top: 50, overlay: 0.6, closeButton: ".modal_close"});

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

            // Calling Register Form
            $("#register_form").click(function () {
                $(".social_login").hide();
                $(".user_register").show();
                $(".header_title").text('Register');
                return false;
            });

            // Going back to Social Forms
            $(".back_btn").click(function () {
                $(".user_login").hide();
                $(".user_register").hide();
                $(".social_login").show();
                $(".header_title").text('Login');
                return false;
            });

        })
    });

});

Tried This one as well.Didn't work.

CODEPEN : http://codepen.io/monkeytempal/pen/VvKLMe Here is the working code in codepen.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tilak Raj
  • 1,369
  • 5
  • 31
  • 64

4 Answers4

3

You need to put it in the doc ready block:

$(function(){

    $("#modal_trigger").leanModal({top : 50, overlay : 0.6, closeButton: ".modal_close" });
    // other code
});

now if you want to trigger the modal, you can use this code in the doc ready block:

$("#modal_trigger")[0].click(); // == document.getElementById('modal_trigger').click();

You just need one doc ready block and first you have to register/bind the leanModal to the anchor then only you can trigger it:

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

   // now you should trigger
   $("#modal_trigger")[0].click();

   // other code put below

});
Jai
  • 74,255
  • 12
  • 74
  • 103
1

You can try like this-

document.getElementById('login_form').click();

document.getElementById('register_form').click();

To trigger any event triggered by that button click with simple JavaScript.

Or by using jQuery like this-

$("#register_form").click();
$("#login_form").click();
$().find("anything_you_want").click();

Update-

For using with Bootstrap - add this events to your click events-

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');

More Info-

$('#your_link_id').click()

From this excellent jquery docs for more information.

Please check it out.

$('#your_link_id').trigger('click');

It should work.

Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161
1

use this code:

   // Plugin options and our code
$("#modal_trigger").leanModal({
        top: 100,
        overlay: 0.6,
        closeButton: ".modal_close"
});

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

        // Calling Register Form
        $("#register_form").click(function() {
                $(".social_login").hide();
                $(".user_register").show();
                $(".header_title").text('Register');
                return false;
        });

        // Going back to Social Forms
        $(".back_btn").click(function() {
                $(".user_login").hide();
                $(".user_register").hide();
                $(".social_login").show();
                $(".header_title").text('Login');
                return false;
        });
});


$( document).ready(function() {
    $("#modal_trigger")[0].click();
});
Supun Praneeth
  • 3,087
  • 2
  • 30
  • 33
  • and this is not working as well.I have given the whole code of the pop up in the post above.Try running this on codepen link .It won't work! – Tilak Raj Feb 02 '16 at 17:16
  • Thanks a lot. Could you please tell be how to open that pop up on login state.. Like right now it opens the pop up. How to open the login page on that pop directly.? – Tilak Raj Feb 03 '16 at 10:17
  • And post the right answer.. I will select that as the right one for other people also :) – Tilak Raj Feb 03 '16 at 10:26
  • done :) and i didn't get what you said, what do you mean by directly? – Supun Praneeth Feb 03 '16 at 10:37
  • As in pop up does come up but what i mean is when pop up comes up.. The item on the pop up are Facebook login and google login.. Is there any way that will show the login page on the pop up instead of the Facebook and Google login ? – Tilak Raj Feb 03 '16 at 10:40
  • :) goodluck and your modle plugin is so poor, i suggest this one is better: http://craftpip.github.io/jquery-confirm/ – Supun Praneeth Feb 03 '16 at 12:06
0
Using simple jquery 

$("#YourLinkID").click();
Aslam Patel
  • 874
  • 6
  • 19