IRHM
IRHM

Reputation: 1326

Pop up Modal Dialog Box

Using this post I've been able to implement a dialog box that appears once the form is loaded. I would however like to change this so that the user clicks a button for the dialog to appear.

I've followed the guidance provided, and removed this line $("#divdeps").dialog('open'); from the Javascript function as instructed, and added it to the 'onclick' event of my button i.e.

<button type="button" value="Upload" onclick="$('#divdeps').dialog('open');">Upload</button>

so my code is now:

<div id="divdeps" style="display: none">This is my div</div>
<button type="button" value="Upload" onclick="$('#divdeps').dialog('open');">Upload</button>
<script> 
$(document).ready(function(){
  $("#divdeps").dialog({
    autoOpen: false,
    show: 'slide',
    resizable: false,
    position: 'center',
    stack: true,
    height: 'auto',
    width: 'auto',
    modal: true
  });

 // $("#divdeps").dialog('open');
});

</script>

However, I can't get this to work on the 'onclick' event of the button. I've been through the instructions quite a few times now and I'm not sure where I'm going wrong.

I just wondered whether someone could perhaps take a look at this please and let me know what I'm doing wrong.

Many thanks and regards

Upvotes: 1

Views: 5113

Answers (3)

Adam Rackis
Adam Rackis

Reputation: 83376

I would do it with the click function of jQuery instead of that dom level 0 handler:

$("#divdeps + button").click(function() { $("#divdeps").dialog('open'); });

Or of course you can give this button an id and do

$("#buttonID").click(function() { $("#divdeps").dialog('open'); });

Either of those sections of code would go in your document.ready handler.


Per Virendra's comment, your original button tag was wrong—you were missing a closing tag, and have mismatched quotes:

<button value="Upload" onclick="$("#divdeps").dialog('open');"</button> 

should have been

<button value="Upload" onclick="$('#divdeps').dialog('open');"> </button> 

Upvotes: 2

user957178
user957178

Reputation: 631

Use this code its working in my application.

PopUpWindow = function (titles, message, redirectURL) {
        document.getElementById('window').innerHTML = message;
        $("#window").dialog({
            resizable: true,
            height: 180,
            title: titles,
            width: 500,
            modal: false,
            open: function () {
                $('.ui-widget-overlay').show();
                $('.ui-dialog-titlebar-close.ui-corner-all').hide();
            },
            buttons: {
                "OK": function () {
                    $(this).dialog("close");
                    if (redirectURL) {
                        window.location = redirectURL;
                    }
                }
            }
        });
    };

div tag

  <div id="window" style="display: none;width:190px"> 

Let me know if you have any problem here.

Upvotes: 0

Robin
Robin

Reputation: 21894

Instead of $("#divdeps").dialog('open'); that you commented out, try:

$("button#give_it_some_id").click(function(e) {
    e.preventDefault();
    $("#divdeps").dialog('open');
})

Upvotes: 1

Related Questions