2013-11-15 2 views
-1

jquery 대화 상자에 문제가 있습니다. 동일한 항목을 여러 번 추가하는 중입니다. 하나의 항목을 한 번만 추가하려고하지만 같은 항목을 여러 번 추가하려고합니다.jQuery 대화 상자에서 중복 제품 제거

내 코드 :

$("#dialog-form").dialog({ 
        autoOpen: false, 
        height: 300, 
        width: 350, 
        modal: true, 
        buttons: { 
         "Submit": function() { 
          var bValid = true; 
          allFields.removeClass("ui-state-error"); 
          bValid = bValid && checkLength(productname, "Product Name", 1, 100); 
          bValid = bValid && checkLength(qty, "Qty", 1, 4); 
          bValid = bValid && checkRegexp(qty, /^[+]?[0-9]*\.?[0-9]+$/, "Qty field allows only Positive numbers"); 
          bValid = bValid && checkLength(price, "Price", 1, 4); 
          bValid = bValid && checkRegexp(price, /^[+]?[0-9]*\.?[0-9]+$/, "Price field allows Only Positive numbers"); 
          //       bValid = bValid && checkRegexp(amount, /^[+]?[0-9]*\.?[0-9]+$/, "Price field allows Only Positive numbers"); 
          //      alert("itemmmm mmmmmmmmm mmmmm " + itemid) 

          if (bValid) { 
           $("#users tbody").append("<tr id='" + ++rowIndex + "'>" + 
            "<input type='hidden' value='" + itemid + "' name='quotationDetails'>" + 
            "<td><input id='med" + rowIndex + "' type='text' value='" + s + "' name='quotationDetailsName' style='border: none;' readonly></td>" + 
            "<td><input id='dos" + rowIndex + "' type='text' value='" + qty.val() + "' name='quotationDetailsQty' style='border: none;' readonly></td>" + 
            "<td><input id='pric" + rowIndex + "' type='text' value='" + price.val() + "' name='quotationDetailsPrice' style='border: none;' readonly></td>" + 
            "<td><input id='amoun" + rowIndex + "' type='text' value='" + qty.val() * price.val() + "' name='amonuttotal' style='border: none;' readonly></td>" + 
            "<td><input type='button' id='" + rowIndex + "' value='Edit' onclick='editRow(this);'></td>" + 
            "<td><input type='button' productname='" + rowIndex + "' value='Delete' onclick='deleteRow(this);'/></td>" + 
            "</tr>");       
           var n = document.getElementById("qty").value; 
           var p = document.getElementById("price").value; 
           var tmpTtl = document.getElementById("tamt").value; 
           var ttl = (parseInt(n) * parseInt(p)) + parseInt(tmpTtl); 
           document.getElementById("tamt").value = ttl; 
           $(this).dialog("close"); 

          } 
         }, 
         Cancel: function() { 
          $(this).dialog("close"); 
         } 
        }, 
        close: function() { 
         allFields.val("").removeClass("ui-state-error"); 
        } 
       }); 

       $("#create-user") 
       .button() 
       .click(function() 
       { 
        ////alert(1); 
        $("#dialog-form").dialog("open"); 
       }); 
       $("#create-user1") 
       .button() 
       .click(function() 
       { 
        $("#dialog-form").dialog("open"); 
       }); 

      }); 

내 DialogForm :

<div id="dialog-form" title=""> 
       <p class="validateTips">All form fields are required.</p> 
       <fieldset> 
        <label for="productname">Product Name</label> 
        <input type="hidden" id="itemid" value="<%= it.getItemId()%>" /> 

        <!-- <input type="text" id="productname" class="text ui-widget-content ui-corner-all"/><p><span id="t"></span></p>--> 
        <select name="productname" id="productname" class="text ui-widget-content ui-corner-all" onchange="productnames(this);"> 

         <option value="">Select Product</option> 
         <% 
          ItemDAO itDAO = new ItemDAO(); 
          List lst = itDAO.getItems(); 
          for (Iterator itm = lst.iterator(); itm.hasNext();) { 
           it = (Item) itm.next(); 
         %> 

         <option value="<%= it.getItemId()%>"><%= it.getItemName()%></option> 
         <% 
          } 
         %> 
        </select> 
        <label for="qty">Qty</label> 
        <input type="text" id="qty" class="text ui-widget-content ui-corner-all" /> 

        <label for="price">Price</label> 
        <input type="text" id="price" class="text ui-widget-content ui-corner-all" /> 
        <!--     <label for="amount">Amount</label> 
             <input type="text" id="amount" class="text ui-widget-content ui-all" />--> 


       </fieldset> 
      </div>   

답변

0

  $("#create-user").click(function() 
      { 
       $("#dialog-form").dialog("open"); 
      }); 

를 작성 시도하고 당신이 생성지고있는 항목을 구체적으로 기재 할 수있는 여러 번

+0

실제로 경우 다음과 같은 항목을 하나 추가합니다. 펜 같은 항목 나는 제품 목록에 해당 항목이 이미 있는지 식별하는 방법을 시간대에 추가 할 수 있습니다. 제게 제안 해주십시오. – Venkatesh

관련 문제