Avatar of cookers
cookers
 asked on

Getting Jquery dialog to work

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
jQuery

Avatar of undefined
Last Comment
cookers

8/22/2022 - Mon
Jon Norman

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();
cookers

ASKER
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 Norman

OK, will try this out on jsfiddle, will get back to you with an answer in a bit.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Jon Norman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
cookers

ASKER
Thanks, next step for me now that is solved is to move from old fashioned AJAX to jquery AJAX..wish me luck