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?
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" type="text/css" media="all" />
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
- <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript"></script>
- <style type="text/css">body{font-size:62.5%;}label,input{display:block;}</style>
- </head>
- <body>
- <ul>
- <li>nr_4121<br /><button id="nr_4121" class="tell-a-friend">Send by email</button></li>
- <li>nr_4122<br /><button id="nr_4122" class="tell-a-friend">Send by email</button></li>
- </ul>
- <script type="text/javascript">
- $(function() {
- $("#dialog-form").dialog({
- autoOpen: false,
- modal: true,
- open: function() {
- var nr = $("button").attr("id");
- $("#dialog-form").dialog("option", "title", nr);
- },
- buttons: {
- 'Send email': function() {},
- Cancel: function() {$(this).dialog('close');}
- },
- close: function() {
- }
- });
- $('.tell-a-friend')
- .button().click(function() {
- $('#dialog-form').dialog('open');
- });
- });
- </script>
- <div id="dialog-form">
- <form><label for="name">Name</label>
- <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
- <label for="email">Email</label>
- <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
- </form>
- </div>
- </body>
- </html>
Any help would be really appreciated.