Advertisement
LonelyShepherd

Cancer form [Лаб. 5.3]

Dec 24th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>Канцер</title>
  6.         <style type="text/css">
  7.       * {padding: 0; margin: 0;}
  8.             .main-wrapper {display: table; margin: 0 auto;}
  9.       label {width: 100px; display: block; margin-bottom: 10px; float: left;}
  10.       input {width: 200px; box-sizing: border-box; float: left; }
  11.       .main-wrapper div {width: 300px; position: relative; clear: both;}
  12.       .main-wrapper div:first-of-type {margin-top: 20px;}
  13.       input + span {position: absolute; display: inline-block; width: 200px; padding-left: 5px; left: 100%; color: red; display: none;}
  14.       .one-empty-boi {box-shadow: 0 0 5px red; border: 2px solid red;}
  15.       .add {clear: both;}
  16.       #selectable {list-style-type: none; width: 100%; clear: both;}
  17.       #selectable .ui-selecting { background: #FECA40; }
  18.       #selectable .ui-selected { background: #F39814;}
  19.       #selectable li { margin-bottom: 3px; padding: 5px;}
  20.       .dialog {font-size: .8em;}
  21.       .dialog div {margin: 10px 0;}
  22.         </style>
  23.         <script src="jquery/jquery.js"></script>
  24.     <script src="jquery/jquery-ui.js"></script>
  25.     <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  26.     <script type="text/javascript">
  27.         $(document).ready(function() {
  28.         var $inputFields = $("input"),
  29.             $addButton = $(".add"),
  30.             $dialog = $(".dialog");
  31.  
  32.         $($inputFields[3]).datepicker({
  33.           changeMonth: true,
  34.           changeYear: true
  35.         });
  36.  
  37.         function fillDialog() {
  38.           var $hobbies = $(".ui-selected"),
  39.               hobbies = "";
  40.  
  41.           for(var i = 0; i < $hobbies.length-1; i++)
  42.             hobbies += $($hobbies[i]).text() + ", ";
  43.           hobbies += $($hobbies[i]).text();
  44.  
  45.           $dialog.html("<div>Name: " + $($inputFields[0]).val() + "</div>" +
  46.             "<div>Surame: " + $($inputFields[1]).val() + "</div>" +
  47.             "<div>Password: " + $($inputFields[2]).val() + "</div>" +
  48.             "<div>DateOfBirth: " + $($inputFields[3]).val() + "</div>" +
  49.             "<div>Hobbies: " + hobbies + "</div>");  
  50.         }
  51.  
  52.         function isEmpty() {
  53.           var empty = false;
  54.           $inputFields.removeClass("one-empty-boi").next("span").hide();
  55.  
  56.           for(var i = 0; i < $inputFields.length; i++) {
  57.             if($($inputFields[i]).val() == "") {
  58.               empty = true;
  59.               $($inputFields[i]).addClass("one-empty-boi").next("span").show();
  60.             }
  61.           }
  62.  
  63.           if(!empty) {
  64.             fillDialog();
  65.             dialog.dialog("open");
  66.           }
  67.         }
  68.  
  69.         var dialog = $dialog.dialog({
  70.           autoOpen: false,
  71.           width: 350,
  72.           modal: false,
  73.         });
  74.  
  75.         $addButton.on("click", isEmpty);
  76.  
  77.         $("#selectable").selectable();
  78.         });
  79.     </script>
  80.     </head>
  81.     <body>
  82.         <div class="main-wrapper">
  83.       <div class="dialog" title="User Info"></div>
  84.       <div>
  85.         <label>Name:</label>
  86.         <input type="text" placeholder="Name"><span>Insert a name</span>
  87.       </div>
  88.       <div>
  89.         <label>Surname:</label>
  90.         <input type="text" placeholder="Surname"><span>Insert a surname</span>
  91.       </div>
  92.       <div>
  93.         <label>Password:</label>
  94.         <input type="password" placeholder="Password"><span>Insert a password</span>
  95.       </div>
  96.       <div>  
  97.         <label>DateOfBirth:</label>
  98.         <input type="text" placeholder="Date Of Birth"><span>Insert a date</span>
  99.       </div>
  100.       <div>
  101.         <span style="display: block; float: left; width: 100%; margin: 30px 0 15px 0;">Select your hobbies</span>
  102.         <ul id="selectable">
  103.           <li class="ui-widget-content">Gaming</li>
  104.           <li class="ui-widget-content">Sports</li>
  105.           <li class="ui-widget-content">Watching Tv</li>
  106.           <li class="ui-widget-content">Sleeping</li>
  107.           <li class="ui-widget-content">Hiking</li>
  108.           <li class="ui-widget-content">Skiing</li>
  109.           <li class="ui-widget-content">Dancing</li>
  110.         </ul>
  111.       </div>
  112.       <div style="margin-top: 40px;"><button class="add">Add my info</button></div>
  113.     </div>
  114.     </body>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement