We help IT Professionals succeed at work.

Getting  Jquery dialog to work

cookers
cookers asked
on
308 Views
Last Modified: 2012-05-30
I would like some help in getting Jquery Dialog working. So far I have used Jquery tutorials to get going but have reached a bit of a cul de sac. I am trying to fire a JQ dialog from a javascript and  not from a click. The dialog fires OK but im at a loss trying to catch its returns.  So I have the following.

In the document ready script

jQuery('#remove_dialog').dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false,
            buttons: {
                "OK": function() {
            jQuery(this).dialog("close");
                    return true
                },
                "Cancel": function() {
                    jQuery(this).dialog("close");
                return false
                }
            }
        });
      
and a div with the dialogue
<div id="remove_dialog" title="Confirm Action ">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 0 0;"></span> You clicked to remove car:</p>
<p id="dialog-rego"></p>
<p>Click "OK" to remove.</p>
<p>If not, click Cancel.<p>
</div>
and the function which fires the dialog

function remove(){
var iFrame =  document.getElementById('formsframe')
OForm=iFrame.contentDocument.getElementsByTagName('form')[0]
carreg =  OForm.registration.value;

document.getElementById('dialog-rego').innerHTML=carreg
return jQuery('#remove_dialog').dialog('open');

reggo=loadTextDoc("POST","php/remove.php?q="+carreg,false);
warning(carreg+ " has been removed from the database");
return false;
}
So..how do I catch and interpret the returns from the dialog, control doesnt appear to pass back to the remove function.

Thanks for any help
Comment
Watch Question

Jon NormanInformation Systems Manager
CERTIFIED EXPERT
Top Expert 2012

Commented:
return stops the current script and returns the value you specify, you want:

function remove(){
  var iFrame =  document.getElementById('formsframe')
  OForm=iFrame.contentDocument.getElementsByTagName('form')[0]
  carreg =  OForm.registration.value;

  document.getElementById('dialog-rego').innerHTML=carreg
  if( jQuery('#remove_dialog').dialog('open')){
    reggo=loadTextDoc("POST","php/remove.php?q="+carreg,false);
    warning(carreg+ " has been removed from the database");
    return false;
  }
}

Open in new window


I have left the return false at the bottom of your script, I don't know what you want to return from remove();

Author

Commented:
Thanks..I tried the script you suggested with no luck. The dialog returns [div#remove_dialog.ui-dialog-content] in response to the line " if( jQuery('#remove_dialog').dialog('open'))" and it returns it immediately before a button is selected in the dialog. It is returning data from the div containing the dialog parameters so maybe I should try another way of scripting the dialog
Jon NormanInformation Systems Manager
CERTIFIED EXPERT
Top Expert 2012

Commented:
OK, will try this out on jsfiddle, will get back to you with an answer in a bit.
Information Systems Manager
CERTIFIED EXPERT
Top Expert 2012
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, next step for me now that is solved is to move from old fashioned AJAX to jquery AJAX..wish me luck
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.