How to avoid duplicate in form text fileds before submition

How to avoid duplicate in form text fileds before submition

What I have done is this, but it didn't work.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.  <script src="jquery-1.8.2.min.js" type="text/javascript" ></script>
  5. <form action="save.php" method="post">
  6. <table>
  7.    <tr>
  8.       <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
  9.       <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
  10.     </tr>
  11.     <tr>
  12.       <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
  13.       <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
  14.     </tr>
  15.     <tr>
  16.       <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
  17.       <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
  18.     </tr>
  19.     <tr>
  20.       <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
  21.       <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
  22.     </tr> 
  23. </table>
  24. <button id="my-submit-button">Submit</button>
  25. </form>
  26. </body>
  27. <script>
  28. $(function(){
  29. $('input[name^="text"]').change(function() {
  30.     var $current = $(this);
  31.     $('input[name^="text"]').each(function() {
  32.         if ($(this).val() == $current.val() && $(this).attr('id') != $current.attr('id'))
  33.         {
  34.             alert('duplicate found!');
  35.         }
  36.     });
  37.   });
  38. });
  39.    
  40. </script>
  41. </html>