I sense this may be a problem of scope. I suspect some of your variables may be in global scope and not being destroyed or reset as you might hope.
* Make sure all your variables are declared with the var keyword. * A var declared in a function has function scope. * A variable undeclared by the var keyword has global scope (and lifetime) regardless of where it is first used. * Then there are closures, which I can't get into here. Some suggestions: 1) Run your code through http://jslint.com. That will alert you to many things, including scope. 2) Consider, instead of scattered variables, place your variables in an object literal, and attach that as a property to a scoped object, maybe even the dialog itself. This keeps things clean. Object literals: http://blog.rebeccamurphey.com/2009/10/15/using-objects-to-organize-your-code/ **--** Steve On Jan 4, 4:10 am, jmumby <jason.mu...@gmail.com> wrote: > Im not a pro by any means just playing around but I seem to be getting pretty > random results from Dialog > > A bit of background. I have made a page that is a parent page it has the DTD > declarations in it as wells a div that contains the navagation and a div > container that loads the pages depending on what menu items is selected in > the navagation. The main page has the includes for jquery, ui and another > page which has my specific javascript. > > One of my pages has field which the users fill in to populate a drop down > menu. I declare the dialogs as below within the page chosen from the > navagation, so it is not in the parent page. > > <script type="text/javascript"> > var index = function () { > var _index; > return function (ind) { > if (typeof ind !== "undefined") { > _index = ind; > } > return _index; > }; > > }(); > > function delete_dialog(item) > { > index(item); > $('#dialog').dialog('open'); > > } > > $(function () { > > $("#dialog").dialog({ > bgiframe: true, > autoOpen: false, > height: 190, > width: 355, > modal: true, > buttons: { > 'Yes, delete this item': function () { > delete_item(index()) > }, > 'No, do not delete this item': function () { > $(this).dialog('close'); > } > > } > }); > $("#warning").dialog({ > bgiframe: true, > modal: true, > autoOpen: false, > buttons: { > Ok: function() { > $(this).dialog('close'); > } > } > }); > > }); > > </script> > > One of the above dialogs is a delete confirmation the other is just a > general message dialog which I set the text inside from another script. > > <div id="warning" title="Message from site"> > <p> > > </p> > <p id="alert_message">There should be some sort of message here.</p> > </div> > > Basically I target #alert_message with what ever the message is, for example > if someone adds an item it says "Item added". The add script that is > included on the parent page is as follows. > > function add_item(item){ > var item_value = "#"+item; > var value = $(item_value).val(); > $.post("rpc.php", { > method: "add_item", > item:item, > value:value > }, > function(data,textstatus){ > loadContent('#menu','menu.php?new=new'); > if(data.item) > { > $(data.item).append(data.data); > $("#warning").dialog('open'); > $("#alert_message").empty().append(data.message); > $(item_value).val(""); > } > else if (data.message) > { > $(item_value).val(""); > $("#warning").dialog('open'); > $("#alert_message").empty().append(data.message); > } > > }, "json"); > return false; > > } > > My problems seem to stem from the form. If I were to add an item from a > field navigate to another page and then go back to this page and click add > item it will add the same item again even though that field is empty. > > Some times I can add an item the dialog will pop up but the message is the > default one rather than the appended one. > > Everything will work perfectly if I do a refesh before doing anything else. > Do I need to somehow work out a way to destroy the dialogs if a user > navagates away? > > I guess Im just after some direction to get the most reliable results from > dialog. > > Thx > > -- > View this message in > context:http://old.nabble.com/UI-dialog-random-results-tp27010360s27240p27010... > Sent from the jQuery UI Discussion mailing list archive at Nabble.com. -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery...@googlegroups.com. To unsubscribe from this group, send email to jquery-ui+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en.