Advertisement
Guest User

Untitled

a guest
May 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.26 KB | None | 0 0
  1. <script>
  2.     $( function() {
  3.       var dialog, form
  4.  
  5.       function editField() {
  6.         //redirection to another page
  7.  
  8.         $('#dialog-form').click(function(e){
  9.           e.preventDefault();
  10.           if($('#abreviation').val() == "" || $('#description').val() == "" || $('#largeur').val() == "" || $('#longueur').val() == "" ){
  11.             alert("Vous n'avez pas rempli tout les champs!")
  12.           } else {
  13.             let abre = $('#abreviation').val();
  14.             let desc = $('#description').val();
  15.             let larg = $('#largeur').val();
  16.             let long = $('#longueur').val();
  17.  
  18.             $.ajax({
  19.               type:"POST",
  20.               cache:false,
  21.               url:"testsql.php",
  22.               data: 'abre='+ abre  +'&desc='+ desc + '&larg='+ larg +'&long='+ long,   // multiple data sent using ajax
  23.               success: function (responseJson) {
  24.                 if(!responseJson){
  25.                     alert('An error occured!')
  26.                 } else {
  27.                     let arr = JSON.parse(responseJson);
  28.                     let html = "<tr><td>"+arr[0]+"</td><td>"+arr[1]+"</td><td>"+arr[2]+"</td><td>"+arr[3]+"</td></tr>";
  29.                     console.log(html);
  30.                     $('#tbody').append(html);
  31.                 }
  32.               }
  33.             });
  34.           }
  35.         });
  36.  
  37.         dialog.dialog( "close" );
  38.       }
  39.  
  40.       dialog = $( "#dialog-form" ).dialog({
  41.         autoOpen: false,
  42.         height: 400,
  43.         width: 350,
  44.         modal: true,
  45.         buttons: {
  46.           "Confirm": editField,
  47.           Cancel: function() {
  48.             dialog.dialog( "close" );
  49.           }
  50.         }
  51.       });
  52.  
  53.  
  54.       $('#mailbutton').click(function() {
  55.         dialog.dialog( "open" );
  56.       });
  57.  
  58.     });
  59.   </script>
  60. </head>
  61. <body>
  62.  
  63. <div id="dialog-form" title="Edit">
  64.   <form id="formtest">
  65.     <fieldset>
  66.       <label for="abreviation">Abréviation</label>
  67.         <input type="text" name="abreviation" id="abreviation" value="M1" class="text ui-widget-content ui-corner-all">
  68.       <label for="description">Description</label>
  69.         <input type="text" name="description" id="description" value="Rack Mistrello" class="text ui-widget-content ui-corner-all">
  70.       <label for="largeur">Largeur</label>
  71.         <input type="number" name="largeur" id="largeur" value="390" class="text ui-widget-content ui-corner-all">
  72.       <label for="longueur">Longueur</label>
  73.         <input type="number" name="longueur" id="longueur" value="6" class="text ui-widget-content ui-corner-all">
  74.  
  75.       <!-- Allow form submission with keyboard without duplicating the dialog button -->
  76.       <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
  77.     </fieldset>
  78.   </form>
  79. </div>
  80.  
  81. <div id="users-contain" class="ui-widget">
  82.   <table id="users" class="ui-widget ui-widget-content">
  83.     <thead>
  84.       <tr class="ui-widget-header ">
  85.         <th>Abréviation</th>
  86.         <th>Description</th>
  87.         <th>Largeur</th>
  88.         <th>Longueur</th>
  89.         <th></th>
  90.       </tr>
  91.     </thead>
  92.     <tbody id="tbody">
  93.       <tr>
  94.         <td>M1</td>
  95.         <td>Rack Mistrello</td>
  96.         <td>390</td>
  97.         <td>6</td>
  98.         <td id="mailbutton">Edit</td>
  99.       </tr>
  100.     </tbody>
  101.   </table>
  102. </div>
  103. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement