How to avoid duplicate in form text fileds before submition
What I have done is this, but it didn't work.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <script src="jquery-1.8.2.min.js" type="text/javascript" ></script>
- <form action="save.php" method="post">
- <table>
- <tr>
- <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
- <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
- </tr>
- <tr>
- <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
- <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
- </tr>
- <tr>
- <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
- <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
- </tr>
- <tr>
- <td class='text-right'><input type='text' class='input-xlarge' name='model[]' id='model' value='' placeholder='Model'></td>
- <td class='text-right'><input type='text' class='input-xlarge' name='engine_number[]' id='engine_number' value='' placeholder='Engine No'></td>
- </tr>
- </table>
- <button id="my-submit-button">Submit</button>
- </form>
- </body>
- <script>
- $(function(){
- $('input[name^="text"]').change(function() {
- var $current = $(this);
- $('input[name^="text"]').each(function() {
- if ($(this).val() == $current.val() && $(this).attr('id') != $current.attr('id'))
- {
- alert('duplicate found!');
- }
- });
- });
- });
-
- </script>
- </html>