开发者

jquery dialog is clearing my form fields and I need to return a value from a jquery dialog

1.) I have a jQuery dialog that is opened whenever a particular textbox is focused. The dialog's contents are loaded from ajax and the unique ID of the textbox that was focused is passed in the ajax call (like this):

$('[name=start_airport[]],[name=finish_airport[]]').click(function(){

  var id = $(this).attr('id开发者_运维问答');

  if($('#use_advanced_airport_selector').attr('checked')) {

    $('#advanced_airport_selector').dialog({

      open : function() {

        $(this).load('/flight-booker/advanced-airport-selector.php?callerID='+id);

      }

    });

    $('#advanced_airport_selector').dialog('open');

  }

});

(where advanced_airport_selector is an empty div)

THAT PART WORKS FINE. However, when I make my ajax call within my dialog, all my form values are reset! No matter what I do, when that dialog opens, all form values are reset (not just the value of the textbox that was focused). I simply don't understand what would cause this behavior!

But that's only issue #1.

2.) I need to be able to return a value from that dialog box. I am passing the ID in the ajax query so that I can use a jquery selector to update the caller's value after certain actions are performed within the dialog box. However, I can't actually access that textbox because of DOM_ERRORS that I've never come across. It doesn't make any sense!

There's way to much code to post, and it's really hard to explain, so sorry if I'm unclear as to what I'm asking.


The DOM errors in problem #2 might be caused by the square brackets in your selector. Square brackets ( [ and ] ) are special characters in jQuery, so you should escape them like this:

$('[name=start_airport\\[\\]],[name=finish_airport\\[\\]]').click(function(){
...
});

From http://api.jquery.com/category/selectors/:

If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \\. For example, if you have an element with id="foo.bar", you can use the selector $("#foo\\.bar").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜