Or Weinberger
Or Weinberger

Reputation: 7472

jQuery dialog not working properly

I have the following script:

<script type="text/javascript">
$( "#addLocation" ).dialog({
            autoOpen: false,
        modal: true,
        height: 700,
        width: 550,
        buttons: {
            "Add Location": function() {
                document.forms["mapform"].submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
});
</script>

<script type="text/javascript">
function showLocationDialog() {
    $("#addLocation").dialog("open");
}
</script>

<div id="addLocation" style="display:none;">
<form action="" method="post" name="mapform">
<input type="text" name="name" />
<input type="submit" />
</form>
</div>

<button onclick="javascript:showLocationDialog();">Add an address</button>

The button does not open the dialog and I cannot understand why.. can anyone assist?

Thanks,

Upvotes: 1

Views: 1856

Answers (3)

stephen776
stephen776

Reputation: 9234

another thing to try...

remove the display:none css from the addLocation div..the dialog will take care of hiding everything once its initialized on document.ready

Upvotes: 0

davin
davin

Reputation: 45525

Wait for the DOM to be ready.

Stick your .dialog() code in a $(document).ready() or $() block

Upvotes: 3

karim79
karim79

Reputation: 342635

1 - Put the .dialog() initialization into a $(document).ready() { ... });.

2 - Remove the extra comma from after the buttons value:

buttons: {
            "Add Location": function() {
                document.forms["mapform"].submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }, <-- remove this, causes IE to spontaneously combust

Upvotes: 1

Related Questions