hello my lovely friends of daniweb commuty.
i have i jquery code of login popup basicaly it work when we click on a link to call it. but i want to excute it if a field is empty for it, i have add a code before $('a.login-window').click(function() and that code check if the var is empty "= null" and it excute the whole like we have click on the liink to call the popuplogin code, but it don't work here is my code please help me i don't what i made mistake
BASICALY THE CODE START FROM LINE 8 BEFORE THE LINE CODE IS THE CODE WHO I HAVE ADD AND IT IS ORIGINAL FROM JAVACRIPT AND NOT JQUERY MAYBE THERE IS THE PROBLEM??

$(document).ready(function() {
        {
    var client=document.forms["formulaireajout"]["client"].val;
    if (client==null || client=="")
      {

    }
    $('a.login-window').click(function() {

                //Getting the variable's value from a link 
        var loginBox = $(this).attr('href');

        //Fade in the Popup
        $(loginBox).fadeIn(300);

        //Set the center alignment padding + border see css style
        var popMargTop = ($(loginBox).height() + 24) / 2; 
        var popMargLeft = ($(loginBox).width() + 24) / 2; 

        $(loginBox).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);

        return false;
        });

    // When clicking on the button close or the mask layer the popup closed
    $('a.close, #mask').live('click', function() { 
      $('#mask , .login-popup').fadeOut(300 , function() {
        $('#mask').remove();  
    }); 
    return false;
    });
    }
    });

I'm not sure if I understand what you're trying to accomplish. One thing I noticed was you're using the jQuery .val for a javascript call, should be .value instead. If you want the if statement you provided to open your login if the if evaluates to true you can do this:

var client=document.forms["formulaireajout"]["client"].value;
if (client==null || client=="")
{
  $( "a.login-window" ).trigger( "click" );
}

If not can you provide some more information as to what you're trying to do? As well as what is ["client"] is it a text box, does it have an id?

hello thank you for reply.
what i want is onSubmit if field client is empty to show login popup box my popup box work righ but i just want to make it automatic if user is not login and he's trying to submit the show the popup box.
i have edit the first code here is the secode something hapen but the popup is not shown. how to add onSubmit before if and how to call $(a.login-window).click(function(){

and to get variable's value from onsubmit and not from a link like below comment in code.

$(document).ready(function() {
    {
        var client = ($('').val());
if (client==null || client=="")
  {


            //Getting the variable's value from a link 
    var loginBox = $(this).attr('href');

    //Fade in the Popup
    $(loginBox).fadeIn(300);

    //Set the center alignment padding + border see css style
    var popMargTop = ($(loginBox).height() + 24) / 2; 
    var popMargLeft = ($(loginBox).width() + 24) / 2; 

    $(loginBox).css({ 
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    // Add the mask to body
    $('body').append('<div id="mask"></div>');
    $('#mask').fadeIn(300);

    return false;
    };

// When clicking on the button close or the mask layer the popup closed
$('a.close, #mask').live('click', function() { 
  $('#mask , .login-popup').fadeOut(300 , function() {
    $('#mask').remove();  
}); 
return false;
});
}
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.