1

I'm loading a customer info page using jQuery. There's a list of customers with a link next to it:

<a href="#" onclick="load_customer(<?php echo $c->id; ?>);return false;">View</a>

That triggers this function:

function load_customer(id) {
  $("#dashboard").load('get_info/' + id);
}

That works perfectly. On the page I'm loading, I have a jQuery UI modal dialog form for adding new information.

<div id="addinfo">
  <form><input type="hidden" name="customer_id" value="<?php echo $c->id; ?>" /></form>
</div>

My javascript:

  $("#addinfobutton").click(function(){
            $("#addinfo").dialog("open");
            return false;
   });
   $("#addinfo").dialog({
            autoOpen:false,
            width:400,
            height:550,
            modal: true
   });

When you select a customer the first time, it populates the hidden field correctly, but then it stays the same even after selecting other customers.

I thought that by loading a new customer page, the form would reset as well... but apparently it's being stored/cached somewhere. If I echo the ID anywhere else in the page, it shows correctly... just not in the "addinfo" div.

Any help/suggestions would be appreciated! Thanks!

1
  • I assume you are loading a new customer page through ajax? and thats replacing the #addinfo div too? Commented Dec 20, 2010 at 19:56

3 Answers 3

1

JQuery dialog's dont reload the content for you when you open them. I tend to have an AJAX call replacing the content of the div that the dialog is on (or tweakng some values in it) when the dialog is opened.

If you want a hidden field, then I wouldn't put it within the dialog, you should be able to retrieve the value from outside the dialog.

Sign up to request clarification or add additional context in comments.

Comments

0

After some more researching, it seems the dialog is being cached client-side after it's called. So to get around that, I just added the customerId to the end of the popup div's ID name... so each customer page will have a unique dialog ID.

However, if it's caching each of those dialogs, won't there be a performance loss if you open quite a few? How can you clear them without having to do a full page refresh?

Comments

0

I guess if the #addinfo div is updated it should capture the new content...anyway this would destroy the dialog after closing it to insure a new instance will be created:

$("#addinfobutton").click(function(){
    openDialog('#addinfo');
    return false;
});
function openDialog(elm) {
    $(elm).dialog({
        autoOpen:true,
        width:400,
        height:550,
        modal: true,
        close: function() {
            $(this).dialog('destroy');
        }
    });
}

4 Comments

Thanks! With that code though, since it doesn't explicitly state with element is the dialog, it actually displays the div on the page. Also, when I tried to destroy the dialog before... it wouldn't work on any other clicks.
I didn't get you here? "since it doesn't explicitly state with element is the dialog, it actually displays the div on the page" does this mean the code above worked for u or not? :-) if it works, please accept the answer and if not elaborate more to be able to help you..
Sorry, no it didn't work. The div containing the form for the dialog is showing up on the page when I use it. I only want it to show when I click the button.
I didn't get your point? are you setting it to display: none; ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.