0

Hi i have been struggle with this code since 1 week now. I cant figure out how i can alert newsArray[i].Title when i push the button for the dialog.

the function SaveUserToList is just a example, i have a lot of code there. The only thing right now is i must get the value from the Title in the newsarray.

         for(var i = 0; i< newsArray.length; i++){
                 $(cloneModalContent).dialog({
                                      resizable: true,
                                      width: "auto",
                                      title: newsArray[i].Title,
                                      modal: true,
                                      buttons: {
                                         Cancel: function() {

                                                 $(this).dialog('close');
                                                 },
                                      'Confirm': function() {


                                                 SaveUserToList();
                                                 $(this).dialog('close');
                                        }
                                    });
                         } 
        function SaveUserToList(){
          alert(newsArray[i].Title);
        }
Anders
  • 185
  • 2
  • 10

1 Answers1

0

What about passing in the dialog title:

     for(var i = 0; i< newsArray.length; i++){
         $(cloneModalContent).dialog({
                        resizable: true,
                        width: "auto",
                        title: newsArray[i].Title,
                        modal: true,
                        buttons: {
                            Cancel: function() {
                               $(this).dialog('close');
                            },
                            'Confirm': function() {
                               SaveUserToList($(this).dialog( "option", "title" ));
                               $(this).dialog('close');
                            }
                        });
    } 
    function SaveUserToList(title){
      alert(title);
    }
J.Wells
  • 1,749
  • 12
  • 13
  • Yes, i tryied it. I have tryied it before also – Anders May 22 '14 at 17:35
  • Thank you so much, you made my day seriously. Can you describe why it worked with that code? – Anders May 22 '14 at 20:33
  • The `.dialog()` plugin has a method called [option](http://api.jqueryui.com/dialog/#method-option), which returns any of the config parameters of the dialog (like `title`, `autoOpen`, `width`, `modal`,`resizable`, etc). `$(this)` in that context is a handle to the dialog in scope. – J.Wells May 23 '14 at 03:30