3

I have a button, onclick of that i want to display the modal pop up window. Here's what i have done- Window is displayed for 2 seconds and then it vanishes! what might be the problem?

  <script>
             $j=jQuery.noConflict();

              $j(document).ready(function() {

                 $j('input[id$=loginbtn]').click(function(event) {

                    $j('#login').dialog({autoOpen: shallIOpen(), 
                            title: 'Login:',
                             resizable: false, width: 600,height: 200,
                             autoResize: true, modal: true,draggable: true,
                            buttons: [ { text: "Ok", click: function() { $j( this).dialog( "close" ); }} ] })  
         });
    });

         function shallIOpen(){
             if({!logindisplay}){
                  return true;
             }
             else{
                 return false;
             }
         }

<body>
         <apex:form >
         <apex:commandButton value="Click Here to Login" id="loginbtn"  action="{!login}"/>
         </apex:form>
</body>    

logindisplay is a boolean declared in the controller

public boolean logindisplay{get;set;}
//constructor
public jPopUpController(){
    logindisplay=true;
}
//method called when clicked on the button
public void login(){
    logindisplay=true;

}

Where have i gone wrong? Pop is appearing for only 2 secods and it is disappearing! when i clicked on the button.

  • 3
    Perhaps the underlying button submit is causing this; adding event.preventDefault() to your click function should stop that. – Keith C Apr 28 '14 at 13:19
  • @KeithC Don't forget to promote this comment to an answer. – Alex Tennant Apr 28 '14 at 18:33
5

Perhaps the underlying button submit is causing this; adding event.preventDefault() to your click function should stop that.

  • Adding event.preventDefault() effect the action attribute of the <apex:commandButton action={!loginmethod} value="Click to Login" />. Any idea of an alternative method so that method defined in the controller is called after i click the command button? – Akash Nidhi P S Apr 29 '14 at 6:20
  • @AkashNidhiPS I would assume that you want the controller method called when your dialog OK is clicked? You can use apex:actionFunction for that - see e.g. salesforce.com/us/developer/docs/pages/Content/…. – Keith C Apr 29 '14 at 8:55
  • Yea i need to call <apex:actionfuntion> using onClick attribute. And need to call a method from action function. Thanks for the reply :) – Akash Nidhi P S Apr 29 '14 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.