2016-03-24 1 views
-1

私は、配列を介してフィールドを送信してユーザーを指定する前にこれらのフィールドを検証し、何も追加されていないため、動的テキストフィールドを生成するコードを調査しました。私はこれまで行ってきたことのリンクを残す。 を検証しますか?

<label for="PASIVOS">Data Enter</label> 
    <div class="input_fields_wrap1"> 
<input class="add_field_button1" type="button" value="+ Add" /> 
    </div> 

のyこのコードはjQuery

$(document).ready(function() { 
    var max_fields  = Infinity; //maximum input boxes allowed 
    var wrapper1    = $(".input_fields_wrap1"); 
    var add_button1  = $(".add_field_button1"); //Add button 

    var x = 1; //initlal text box count 
    $(add_button1).click(function(e){ //on add input button click 
     e.preventDefault(); 
     if(x < max_fields){ //max input box allowed 
      x++; //text box increment 
      $(wrapper1).append('<div>Product <input type="text" name="Product[]"/> Price <input type="text" name="Price[]"/> Quantity <input type="text" name="Quantity[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box 
     } 
    }); 

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


}); 

https://jsfiddle.net/sarrhen/L6kdzLco/

私が欲しいものをjQueryを使って非常に良いではないよにアラートを表示することですフィールドが必要であることを示すテキストフィールドのペアd

+0

が何かを成し遂げるだけ最初の入力を行うこと私と他者を検証:中として

if(element1.isNumeric() && element2.isNumeric()){ //do what you want to do .... 

別のオプション、正規表現を使用することです。その場合はそうは以下のようにあなただけの、jquery's .isNumeric() functionを使用することができます生成しないでください http://jsfiddle.net/sarrhen/6cuu4rpw/ –

答えて

0

私が間違っている場合は私を修正しますが、ユーザーがテキストフィールドのいくつかに数字を入力する方法を尋ねていますか?

var re = /^\d+$/; 
if(re.test(element1)) { //test whether element1 is an int 
    //do what you want to do 
.... 
+0

私はjqueryが欲しいのは、フィールドが必要であることを示すテキストフィールドのペアに警告を表示することです –

+0

ただしvalidatとして少なくとも入力されたテキストが生成されるとき、私はそれがeson必須フィールドと言う必要がある –

0
accomplish something but only the first input validates me and others that do not generate could help me 

http://jsfiddle.net/sarrhen/6cuu4rpw/ 
関連する問題