problem using attr

problem using attr

I have in my page a button that onclick opens a dialog (add-to-blacklist_dialog).
In this dialog, the user has a textbox to enter some text and then hits "Ok"

on the Ok click, a second dialog (confirm_word_add_dialog) opens to confirm what the user entred.

The problem is when the user hits "cancel" and returns to the first dialog and changes the text the hits "Ok" of the first dialog,
the "new text" entred is not taken into consideration and i still have the old text.

Any Ideas?? thanks in advance 

Here isa snippet of my html code
  1. <button id="add-word"
  2.     class="ui-button ui-state-default ui-corner-all">add a word
  3. </button>
  4.  
  5. <div id="add-to-blacklist_dialog"
  6.     title="Add a word to list">
  7.  
  8.  
  9. <form>
  10. <fieldset><label for="word">Word to add</label> <input
  11.     type="text" name="word" id="word"
  12.     class="text ui-widget-content ui-corner-all" /></fieldset>
  13. </form>
  14. </div>
  15.  
  16. <div id="confirm_word_add_dialog"
  17.     title="Confirm Adding word?">
  18. <p id="word_add_confirm_message"
  19.     class="ui-icon ui-icon-alert"
  20.     style="float: left; margin: 0 7px 20px 0;"></span>Would you really want
  21. to add <a class="replacement"></a> to the list of blacklisted words ?<br
  22.     style="height: 40px">
  23. All documents conatning the word <a class="replacement"></a> will be deleted</p>
  24. </div>


and a snippet of my function


  1. $( function() {
  2. var word = $("#word");
  3. //some code
  4. $("#add-to-blacklist_dialog")
  5.             .dialog(
  6.                     {
  7.                         bgiframe : true,
  8.                         autoOpen : false,
  9.                         height : 220,
  10.                         modal : true,
  11.                         resizable : false,
  12.                         buttons : {
  13.                             'Ok' : function() {
  14.                                 var bValid = true;
  15.                                 allFields.removeClass('ui-state-error');
  16.      
  17.                                 $('.replacement').replaceWith('<spanstyle=" font-weight: bold;color: red;">' + word.attr("value") +'</span>');
  18.                                     $('#confirm_word_add_dialog').dialog('open');
  19.                                     return false;
  20.                                     $(this).dialog('close');
  21.                                  
  22.                             },
  23.                             Cancel : function() {
  24.                                 $(this).dialog('close');
  25.                             }
  26.                         },
  27.                         close : function() {
  28.                             allFields.val('').removeClass('ui-state-error');
  29.                         }
  30.                     });
  31. $("#confirm_word_blacklist_dialog").dialog( {
  32.         bgiframe : true,
  33.         autoOpen : false,
  34.         height : 200,
  35.         width : 400,
  36.         resizable : false,
  37.         modal : true,
  38.         buttons : {
  39.             Cancel : function() {
  40.                 $(this).dialog('close');
  41.                 word.text(' ');
  42.             },
  43.             'Ok' : function() {
  44.  
  45.                 //some treatment
  46.                  });
  47.             $(this).dialog('close');
  48.             $("#add-to-blacklist_dialog").dialog('close');
  49.              return false;
  50.         }
  51.         },
  52.         close : function() {
  53.  
  54.         }
  55.     });
  56.  
  57. });