Passing a variable to a dialog box

Passing a variable to a dialog box

I need to pass a variable to a dialog box. Since I couldn't find a proper way how to do this, I decided to use the dialog title to store the variable. The problem is, that I can't read the right ID-value which is read from the button's ID. 
Have a look at this code to understand the problem. If you click on either button, you still get the ID-value of the first button.

Btw, is there an other way to pass variables to a dialog box?
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" type="text/css" media="all" />
  5. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
  6. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript"></script>
  7. <style type="text/css">body{font-size:62.5%;}label,input{display:block;}</style>
  8. </head>
  9. <body>
  10. <ul>
  11. <li>nr_4121<br /><button id="nr_4121" class="tell-a-friend">Send by email</button></li>
  12. <li>nr_4122<br /><button id="nr_4122" class="tell-a-friend">Send by email</button></li>
  13. </ul>

  14. <script type="text/javascript">
  15. $(function() {
  16. $("#dialog-form").dialog({
  17. autoOpen: false,
  18. modal: true,
  19. open: function() {
  20. var nr = $("button").attr("id");
  21. $("#dialog-form").dialog("option", "title", nr);
  22. },
  23. buttons: {
  24. 'Send email': function() {},
  25. Cancel: function() {$(this).dialog('close');}
  26. },
  27. close: function() {
  28. }
  29. });

  30. $('.tell-a-friend')
  31. .button().click(function() {
  32. $('#dialog-form').dialog('open');
  33. });
  34. });
  35. </script>

  36. <div id="dialog-form">
  37. <form><label for="name">Name</label>
  38. <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
  39. <label for="email">Email</label>
  40. <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
  41. </form>
  42. </div>
  43. </body>
  44. </html>

Any help would be really appreciated.