Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dialog Box Help

Featured Replies

I'm using dialog boxes for a website I'm doing http://jqueryui.com/dialog/.

 

I'm wanting it to pop up by clicking in two places, for every dialog window to pop up. One is the title and the other is at the read more part (see attached).

 

Here is the code.

 

<div>
        <a class="more" id="pin_1" name="pin_1" title="Text1">Text1</a>
    </div>

    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis orci id erat elementum congue a eu dolor. Mauris et fermentum sem.
    Nullam consequat ligula eu diam malesuada,<br>
    <a class="more" id="pin_1" name="pin_1" title="Text1">Read More »</a></p>

    <div id="dialog_1">
        <p>Phasellus lacinia dignissim mattis. Nullam arcu elit, mollis quis pharetra vitae, egestas nec est. Nunc bibendum scelerisque
        dapibus. Vivamus pulvinar sapien non tincidunt vehicula. Mauris a lacus vulputate, fringilla neque congue, lacinia mi. Mauris
        semper dui mi, ut blandit ante euismod et. Phasellus vitae odio id nisl blandit consectetur ut nec lectus. Class aptent taciti
        sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Mauris sem ante, sollicitudin nec fermentum non,
        pellentesque id lacus.</p>
    </div>

    <div>
        <a class="more" id="pin_2" name="pin_2" title="Text2">Text2</a>
    </div>

    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis orci id erat elementum congue a eu dolor. Mauris et fermentum sem.
    Nullam consequat ligula eu diam malesuada,<br>
    <a class="more" href="#" id="pin_2" name="pin_2" title="Text3">Read More »</a></p>

    <div id="dialog_2">
        <p>Phasellus lacinia dignissim mattis. Nullam arcu elit, mollis quis pharetra vitae, egestas nec est. Nunc bibendum scelerisque
        dapibus. Vivamus pulvinar sapien non tincidunt vehicula. Mauris a lacus vulputate, fringilla neque congue, lacinia mi. Mauris
        semper dui mi, ut blandit ante euismod et. Phasellus vitae odio id nisl blandit consectetur ut nec lectus. Class aptent taciti
        sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Mauris sem ante, sollicitudin nec fermentum non,
        pellentesque id lacus.</p>
    </div>
$( "#dialog" ).dialog({
    
    // Run when the dialog is created.
    create: function( e, ui ) {
        
        // Get the dialog components we need to adjust.
        var $parent = $( this ).parent(),
            $button = $parent.find( ".ui-dialog-titlebar-close" ),
            $title = $parent.find( ".ui-dialog-title" );
        
        // Adjust the dialog title styles.
        $title.css( { width: "auto", margin: "0.44em 0" } );
        
        // Reconfigure the close button to show text, not an icon.
        // Also make style adjustments.
        $button.removeClass( "ui-dialog-titlebar-close" )
               .css( "float", "right" )
               .button( "option", {
                   icons: {primary: false},
                   text: true,
                   label: "Close"
               });
    
    }
    
});

$.fx.speeds._default = 800;
$(function () {
    $("#dialog_1").dialog({
        position: ["center", "center"],
        height: 400,
        width: 700,
        title: 'Links',
        autoOpen: false,
        hide: "explode",
        show: "explode",
        title: "Building Defects"
    });

    $("#pin_1").click(function () {
        $("#dialog_1").dialog("open");
        return false;
    });
});



$.fx.speeds._default = 800;
$(function () {
    $("#dialog_2").dialog({
        position: ["center", "center"],
        height: 400,
        width: 700,
        title: 'Links',
        autoOpen: false,
        hide: "explode",
        show: "explode",
        title: "Building Disputes"
    });

    $("#pin_2").click(function () {
        $("#dialog_2").dialog("open");
        return false;
    });
});

post-24649-0-12202100-1388866543_thumb.png

Edited by Vulcan

Your ids are not unique! #pin_1 and #pin_2 are both duplicated, and only the first one encountered will be recognised.

Either use unique ids, or use classes for a shorter and more generic solution.

Well, if it was me, I'd probably do something along the lines of

<div class='container'>
    <div class='title-block'><a class='the-title open-dialog' href='#'>Title 1</a></div>
    <p>Visible text 1...
        <br /><a class='read-more open-dialog' href='#'>Read More</a>
    </p>
    <div id='dialog_1'>
        <p>The dialog1 text....
        </p>
    </div>
</div>

<div class='container'>
    <div class='title-block'><a class='the-title open-dialog' href='#'>Title 2</a></div>
    <p>Visible text 2...
        <br /><a class='read-more open-dialog' href='#'>Read More</a>
    </p>
    <div id='dialog_2'>
        <p>The dialog2 text....
        </p>
    </div>
</div>

and

jQuery(function($){
    var dialogOnCreate = function( ev, ui ){
            // do whatever needs to be done to each of the dialogs...
            var $parent = $( this ).parent(),
                  $button = $parent.find( '.ui-dialog-titlebar-close' ),
                  $title = $parent.find( '.ui-dilaog-title' );
            // etc, etc...
            };
    $.fx.speeds._default = 800;
    $( '.container' ).each( function(){
        var dialog = $( this ).children( 'div' ).last();
        dialog.dialog({
            height: 400,
            width: 700,
            title: $( this ).find( '.the-title' ).text(),
            autoOpen: false,
            hide: 'explode',
            show: 'explode',
            create: dialogOnCreate
            });
        $( this ).find( '.open-dialog' ).data( 'openDialog', '#' + dialog.attr( 'id' ) )
    }).on( 'click', '.open-dialog', function(){
        $( $( this ).data().openDialog ).dialog( 'open' );
        return false;
    });
});

Please note that this is off-the-cuff, completely untested, and therefore prone to error.

  • Author

I've pasted in the code and it doesn't work.

I've played around adding bits in and cant work out why doesnt work.

 

The text that is meant to be in the dialog box isn't doing anything. (no dialog box is showing)

My code was intended to illustrate the concept - classes instead of ids - rather than the execution. And I did state that it was off-the-cuff (though based on your original) and completely untested (there's at least one typo)!

I would suggest that you use your browser's developer tools to see what errors the browser is reporting, and to see what the javascript is doing to the HTML (if anything). Personally I'm a huge fan of Firefox and its Firebug extension, but other browsers do have tools of their own.

Since you haven't given much of a clue as to what might or might not have been working in your original code, I don't even know whether your page is loading jQuery and jQuery UI correctly, or what versions of either you are using.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.