Friday, May 11, 2012

How to create a modal window in jQuery.

Code Snippet
  1.  
  2. $(function () {
  3.     $('#iDialog').dialog({
  4.         autoOpen: false,
  5.         width: 800,
  6.         height: 400,
  7.         resizable: false,
  8.         modal: true,
  9.         buttons: [{ text: "Ok", click: function () { $(this).dialog("close"); } }]
  10.     });
  11. });
  12.  
  13. $(document).ready(function () {
  14.     $('#show-modal-industry').click(function () {
  15.         $('#iDialog').load(industryUrl, function () {
  16.             $('#iDialog').dialog('open');
  17.         });
  18.  
  19.         return false;
  20.     });
  21. });
  22.  
  23.  
  24. $(function () {
  25.     $('#aDialog').dialog({
  26.         autoOpen: false,
  27.         width: 800,
  28.         height: 400,
  29.         resizable: false,
  30.         modal: true,
  31.         buttons: [{ text: "Ok", click: function () {
  32.             alert('Hello World'); $(this).dialog("close"); } }]
  33.     });
  34. });
  35.  
  36. $(document).ready(function () {
  37.     $('#show-modal-association').click(function () {
  38.         $('#aDialog').load(associationUrl, function () {
  39.             $('#aDialog').dialog('open');
  40.         });
  41.  
  42.         return false;
  43.     });
  44. });

Code Snippet
  1. <div id="iDialog" title="Industry">
  2. </div>
  3. <div id="aDialog" title="Association">
  4. </div>
  5. <script type="text/javascript">
  6.  
  7.     var industryUrl = '@Url.Action("GetIndustryInfo", "Home")';
  8.     var associationUrl = '@Url.Action("GetAssociationInfo", "Home")';
  9.     
  10. </script>

No comments:

Post a Comment