2014-12-28 5 views
1

추가 기능을 호출하는 버튼을 클릭하면 입력이 동적으로 추가되는 양식이 있습니다. 양식이 제출되면 페이지로드시 작성된 입력에만 액세스 할 수 있습니다. 다음 코드를 사용하여이 사실을 두 번 확인했습니다. 실제로 경고는 동적으로 생성 된 ID를 표시하지 않습니다.POST 양식이 동적으로 생성 된 입력

$(document).ready(function() { 
    var max_fields  = 10; //maximum input boxes allowed 
    var wrapper   = $(".input_fields_wrap"); //Fields wrapper 
    var add_button  = $(".add_field_button"); //Add button ID 

    var x = 0; //initlal text box count 
    $(add_button).click(function(e){ //on add input button click 
     e.preventDefault(); 
     if(x < max_fields){ //max input box allowed 
      x++; 
      var printCounter = document.getElementById("product_counter"); 
      printCounter.value = x; 
      //increment 
      $(wrapper).append('<div>' + 
     '<div class="input-group">' + 
     '<span class="input-group-addon">Nom</span>'+ 
        '<input id="vch_invoice_item['+x+']” name="vch_invoice_item['+x+']” value="" type="text" class="form-control" placeholder="">'+ 
       '</div>'+ 
       '<div class="input-group">'+ 
        '<span class="input-group-addon">Description</span>'+ 
        '<input id="vch_invoice_description['+x+']” name="vch_invoice_description['+x+']" value="" type="text" class="form-control" placeholder="">'+ 
       '</div>'+ 
      '<div class="input-group">'+ 
        '<span class="input-group-addon">Prix à l’unité</span>'+ 
        '<input onclick="bindPriceMask(this)" onfocus="bindPriceMask(this)" id="vch_invoice_unitcost['+x+']” name="vch_invoice_unitcost['+x+']” value="" type="text" class="unit form-control" placeholder="">'+ 
       '</div>'+ 
      '<div class="input-group">'+ 
        '<span class="input-group-addon">Quantité</span>'+ 
        '<input onclick="bindQtyMask(this)" onfocus="bindQtyMask(this)" id="vch_invoice_quantity['+x+']” name="vch_invoice_quantity['+x+']” value="" type="text" class="qty form-control" placeholder="">'+ 
       '</div>'+ 
      '<div class="input-group">'+ 
        '<span class="input-group-addon">Taxe Fédérale</span>'+ 
        '<input onclick="bindTaxMask(this)" onfocus="bindTaxMask(this)" id="vch_invoice_fedTax['+x+']” name="vch_invoice_fedTax['+x+']” value="" type="text" class="taxf form-control" placeholder="">'+ 
       '</div>'+ 
      '<div class="input-group">'+ 
        '<span class="input-group-addon">Taxe Provinciale</span>'+ 
        '<input onclick="bindTaxMask(this)" onfocus="bindTaxMask(this)" id="vch_invoice_provTax['+x+']” name="vch_invoice_provTax['+x+']” value="" type="text" class="taxp form-control" placeholder="">'+ 
       '</div>'+ 
     '<a href="#" class="remove_field">Supprimer</a><br><br><br>'+ 
       '</div>'); //add input box 
     } 
    }); 

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text 
     e.preventDefault(); $(this).parent('div').remove(); x--; 
    }) 
}); 

jsfiddle.net/52VtD/9763 크게 내 키보드로 만들어진 내 닫는 따옴표의

+0

개발자 콘솔이 열려 있습니까? 오류가 있습니까? 아무것도? –

+0

make a jsfiddle – AtanuCSE

+0

견적을 확인하십시오. '''대신'''을 사용하십시오 – sectus

답변

1

1.Some을 감사합니다 어떤 도움을 다음과 같이

$('form').submit(function() { 
    alert($(this).serialize()); 
    return false; 
    }); 

스크립트입니다 프랑스와 그러므로 잘못되었습니다. 2. ID로 []를 꺼 냈습니다.

관련 문제