1

I have a link name of "login".

It click "login" jquery dialog will open.

Dialog has two links. If click it link,shows content related to link.

Now i come to my problem. If again i click "login" link,it shows only changed content. But i want initial content only.

This is my one part of code.

$( "#login-form" ).dialog({
                autoOpen: false,
                height: 210,
                width: 360,
                modal: true,
                show: "scale",
                hide: "scale",
                buttons: {
                    "Login": function() {
                        $("#login-frm").submit()                                    
                        },
                    Cancel: function() {
                        $(this).dialog( "close" );
                    }
                }
            });

            $( "#login" ).click(function(event) {
                event.preventDefault();
                $( "#login-form" ).dialog( "open" );
            })

How can i do this?

1
  • Maybe after $("#login-frm").submit() try to close your dialog: $(this).dialog( "close" ). It may help but I don't guaranty. Cheers! Commented Sep 19, 2011 at 10:57

2 Answers 2

1

In your click event you can load default content again. Or else you can keep a copy of default content of the login-form in a hidden div and replace it before dialog opens.

$( "#login-form" ).dialog({
                autoOpen: false,
                height: 210,
                width: 360,
                modal: true,
                show: "scale",
                hide: "scale",
                buttons: {
                    "Login": function() {
                        $("#login-frm").submit()                                    
                        },
                    Cancel: function() {
                        $(this).dialog( "close" );
                    }
                }
            });

            $( "#login" ).click(function(event) {
                event.preventDefault();
                 $( "#login-form" ).html('give the default copy of the dialog here');
                $( "#login-form" ).dialog( "open" );
            })
Sign up to request clarification or add additional context in comments.

Comments

0

Add a class to your login form controls that need to be cleared, say "loginControls" for example. Then, change your $( "#login" ).click() function to be something like this:

 $( "#login" ).click(function(event) {
       event.preventDefault();
       $( ".loginControls" ).each(function (i) {
             this.val('');
             });
       $( "#login-form" ).dialog( "open" );
 });

Note that if you have more than just simple text box controls for your login form, you could do a separate class, such as "loginCheckBoxes", and then iterate through those with $(this).removeAttr('checked'); instead.

This allows you flexibility for various types of controls without the need to write out the entire form HTML in your event handling code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.