views:

35854

answers:

6

I am designing a web page. In that when we click the content of div named mail, a popup window should be shown containing a label email and text box. I searched in google as simple popup in Jquery but the code is weird. Please help me by providing very simple jquery pop up.

+15  A: 

Check out jQuery UI Dialog. You would use it like this:

The jQuery:

$(document).ready(function() {
    $("#dialog").dialog();
});

The markup:

<div id="dialog" title="Dialog Title">I'm in a dialog</div>

Done!

Bear in mind that's about the simplest use-case there is, I would suggest reading the documentation to get a better idea of just what can be done with it.

karim79
Other than Jquery whether i have to include any plugin?? @Karim
Rajasekar
@Rajasekar - You will need to download the jQuery UI bundle and at the very least include ui.core.js and ui.dialog.js to get a Dialogue. If you want the dialogue to be draggable and/or resizable then you will need to include ui.draggable.js and ui.resizable.js.
karim79
Its not working My code is $(document).ready( function(){ $(".menuclick").dialog(); });and my style is.mailclick{ color:#000000; background-color:#FFFFFF; font-size:12px; display:none;}
Rajasekar
A: 

There is a good, simple example of exactly this, here: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial

Evernoob
Other than Jquery whether i have to include any plugin?? @Karim
Rajasekar
+21  A: 

Something this simple doesn't need a plugin. This might look like a lot of code but it's really pretty simple.

First the CSS - tweak this however you like:

a.selected {
  background-color:#1F75CC;
  color:white;
  z-index:100;
}

.messagepop {
  background-color:#FFFFFF;
  border:1px solid #999999;
  cursor:default;
  display:none;
  margin-top: 15px;
  position:absolute;
  text-align:left;
  width:394px;
  z-index:50;
  padding: 25px 25px 20px;
}

label {
  display: block;
  margin-bottom: 3px;
  padding-left: 15px;
  text-indent: -15px;
}

.messagepop p, .messagepop.div {
  border-bottom: 1px solid #EFEFEF;
  margin: 8px 0;
  padding-bottom: 8px;
}

And the JavaScript:

    $(function() {
        $("#contact").live('click', function(event) {
            $(this).addClass("selected").parent().append('<div class="messagepop pop"><form method="post" id="new_message" action="/messages"><p><label for="email">Your email or name</label><input type="text" size="30" name="email" id="email" /></p><p><label for="body">Message</label><textarea rows="6" name="body" id="body" cols="35"></textarea></p><p><input type="submit" value="Send Message" name="commit" id="message_submit"/> or <a class="close" href="/">Cancel</a></p></form></div>');
            $(".pop").slideFadeToggle()
            $("#email").focus();
            return false;
        });

        $(".close").live('click', function() {
            $(".pop").slideFadeToggle();
            $("#contact").removeClass("selected");
            return false;
        });
    });

    $.fn.slideFadeToggle = function(easing, callback) {
        return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);
    };

The appending of the div is an ajax call in my app - you might want to change the append code.

And finally the html:

<a href="/contact" id="contact">Contact Us</a>

Hopefully this code is less weird for you.

Andy Gaskell
+1 very nice code, do you have any other useful jquery code you care to share?
jasondavis
Its Working, Thanks. But im going to include another button call register. when it is clicked, the registration form should popup. For that i included the same function and changed the name of ids and classes. The problem is when i click the close button of the registration form, it toggles the contact form. Need help @jason Davis
Rajasekar
to remove the html you add on close change the close method to$(".close").live('click', function() { $(".pop").slideFadeToggle(); $("#contact").removeClass("selected"); $(".pop").remove(); //add this... return false; });this will correct the problem yo get when you click on the link more then once before closing the popup.nice answer by the way, slick and simple...
Jonx
I just love stackoverflow.. :) Great code @Andy!
Lipis
another +1 from me! love it!
espais
+2  A: 

I use a jquery plugin called colorbox, it is

  1. Very easy to use
  2. lightweight
  3. customizable
  4. the nicest popup dialog I have seen for jquery yet

http://colorpowered.com/colorbox/

jasondavis
A: 

Try out TopUp:

http://gettopup.com

It’s jQuery (soon also Prototype) based and meant to be setup with great ease. The easiest setup is only to include one(!) external Javascript file. It uses one image sprite per layout and doesn’t require a separate stylesheet file to reduce the amount of requests.

The (pixel perfect) look-and-feel is Apple-like with a dashboard and quicklook layout. You can display images, Youtube content, Flash (SWF and FLV), iframes, Ajax content, QuickTime, Windows Media and RealPlayer movies! Display them separately or grouped.

So check it out and give it a try, implementing stylish pop-ups has never been so easy! ;)

Paul Engel
A: 

@Paul Engel: Do you know who created TopUp? ;)

Andron