views:

228

answers:

2

I would like to know if I can use the following JQuery function on a item id located inside a JQuery Dialog.

$('#idofmyfield').val()

Didn't return anything.

A: 

look at the events for dialog

$('.yourDialog').dialog({
   close: function(event, ui) {
       alert($('#idofmyfield').val());
   }
});
andres descalzo
A: 

You may need to adjust your selector id to the markup that is generated by the dialog:

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable">
   <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
      <span id="ui-dialog-title-dialog" class="ui-dialog-title">Dialog title</span>
      <a class="ui-dialog-titlebar-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick">close</span></a>
   </div>
   <div style="height: 200px; min-height: 109px; width: auto;" class="ui-dialog-content ui-widget-content" id="dialog">
      <p>Dialog content goes here.</p>
   </div>
</div>

maybe do this:

$('div.ui-widget-content > #idofmyfield').val();

I had a similar situation pulling JSON data to fill a dialog. My code, which works, looks like the following:

if (jQuery) {
    jQuery(document).ready(function(){      
     jQuery('#dialog').dialog({
      autoOpen: false,
      modal: true,
      width: 690, 
      position: [160, 160]
     }); /* end #dialog */

   /* do some processing and add the following to a click method */
    jQuery.getJSON(json_link, function(json){
        jQuery('.ui-dialog-title').text(json.title);
        jQuery('.ui-dialog-content').html(json.html);
    });

    jQuery('#dialog').dialog('open');
   /* end of click method */


}); /* end document.ready */
}
Jim Schubert