-1

i newbie this my first project,I don't know how to resolve any problems about the repetition of data i have an input page. it consist of 2 textfield:

  1. Model,

  2. Serial,

and one combobox: 1. line.

i want if there is input twice, I mean here is a double input data, will be out warning "data already exists".

how do i do that?i try like this but doesn't work:

 $("#input").click(function() {
         if($("#submit").valid()) {
                 var params=$("#submit").serialize();
                 $.ajax({
                         type:"post",
                         url:"process1.php",
                         data:params,
                         cache :false,
                         async :false,
                         success : 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('data already exists!');
                                                    }
                                          });
                                    });
                                  $("#showmodel").val($("#model").val());
                                  $("#showline").val($("#line").val());
klox
  • 2,089
  • 11
  • 38
  • 65

2 Answers2

0

look at this answer:

prevent Duplicate values using Jquery Validation

$(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('data already exists!');
        }

    });
  });
});
Community
  • 1
  • 1
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
0
$(function() {
        $("#input").click(function(e) {
            var itemExists = false;
            var txt = $("#Text1").val();
            e.preventDefault();
            $("#Select1 option").each(function() {
                if ($(this).text() == $.trim(txt)) {
                    itemExists = true;
                    alert('Item already exists');
                }
            });

          if (!itemExists) {
          $("#Select1").append("<option value=\"1\">" + txt + "</option>");
          $("#Text1").val('');
          }
        });
    });           
klox
  • 2,089
  • 11
  • 38
  • 65