user3550981
user3550981

Reputation: 37

PopUp a Modal using jQuery

I want to popup my login modal on Search click if loginStatus == false, using jQuery.

I.e. if user is not logged in, I want him to login first.

        $('#serviceSelect').on('click', function(event) {
        if (found == 0) {
            alert("Sorry donot exist")
        }
        if(found ==1)
            {
            var status=sessionStorage.getItem('isLoggedIn');
            //alert(status);
            if(status==true){
                alert("Logged in");

            /*--------------    Specify the Questionnare link here -------------*/
            }
            else{
                alert("Logged out");
                /*$('#serviceSelect').attr('data-target','#login-modal');*/

                var modal = $("#login-modal");
                modal.style.display = "block";
            }
            }
         });

This is the list item which popus the login if user wants to login by himself .

       <li class="sidebar-brand" id="loginref"><a href="#"
                data-toggle="modal" data-target="#login-modal"
                data-backdrop="static">

Login Modal div:

    <div class="modal fade" id="login-modal" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel" aria-hidden="true"
    style="display: none;">

Update:

This is popping the modal, but the js of the modal is not attached with the modal.

i.e, There is a login.js which executes on login modal. By popping modal using this, that js is not being executed.

         modal.modal('show');

Upvotes: 0

Views: 574

Answers (2)

madalinivascu
madalinivascu

Reputation: 32354

Use bootstrap .modal('show');

$('#serviceSelect').on('click', function(event) {
        if (found == 0) {
            alert("Sorry donot exist")
        }
        if(found ==1)
            {
            var status=sessionStorage.getItem('isLoggedIn');
            //alert(status);
            if(status==true){
                alert("Logged in");

            /*--------------    Specify the Questionnare link here -------------*/
            }
            else{
                alert("Logged out");
                /*$('#serviceSelect').attr('data-target','#login-modal');*/

                var modal = $("#login-modal");
                modal.modal('show');
            }
            }
         });

mote info on bootstrap

Upvotes: 1

Shibon
Shibon

Reputation: 1574

try this code

$('#login-modal').modal('show');

Upvotes: 1

Related Questions