Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are the changes immediately reset when a dialog window is opened?

I want to open a dialog, that loads the code of another page. This works so far. Now i want to set a select of the loaded dialog to one of its options and than disable (lock) it. But every change i make with JQuery is immidiatly reseted after the dialog is opened.

JavaScript Function:

function dialog(type) {
    $(".dialog").dialog({
      resizable: true,
      height: "auto",
      width: 800,
      modal: true,
      open: function () {
        $(this).load("../SearchPage/search_page.jsp"); 
        setDialogType(type);    
      }, 
    });    
  } 
  
function setDialogType(type) {
    $(".selectbox").empty();
    switch(type) {
        case "race":
            $(".selectbox").append('<option value="Race">Race</option>');
            break;
        case "class":
            $(".selectbox").append('<option value="Class">Class</option>');
            break;
        case "background":
            $(".selectbox").append('<option value="Background">Background</option>');
            break;
    }   
}

Select-Tag in the loaded HTML:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<select name="Auswahl" style="width: 100%" class="selectbox search">
    <option value="Race">Race</option>
    <option value="Class">Class</option>
    <option value="Background">Background</option>
</select>

>Solution :

I believe you need to wait for the content to load and only then call the setDialogType().
To wait for it to load, you need to pass a callbacak to load()

function dialog(type) {
  $('.dialog').dialog({
    resizable: true,
    height: 'auto',
    width: 800,
    modal: true,
    open: function () {
      $(this).load('../SearchPage/search_page.jsp', function () {
        setDialogType(type); 
      }); 
    }
  });
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading