开发者

validate dynamically added textbox

In the below code how to validate for null values for only the dynamically added text box i.e,r_score1,r_score2.........

  <script>
开发者_如何学Go   function validate()
   {
      //How to validate the r_Score.. textfields
   }
  $(document).ready(function() {
   for(var i=0;i< sen.length;i++)
   {
     row += '<input type="text" name="r_score'+i+'" id="r_score'+r_count+'" size="8" />';
    }
   $('#details').append(row);
   });
   </script>
   <div id="details"><input type="text" name="score' id="score" size="8" /></div>
  <input type="button" value="Save" id="print" onclick="javascript:validate();" />


Give the text boxes a class name and use class selector

function validate()
   {
      var boxes = $("#details input:text.classname");
      boxes.each(function(){
          var currentVal = $(this).val();
          // do your validation here
      });
   }


$("#details input[name^='r_score']").each(function(nr){

    if($(this).val() === "") alert("Field "+(nr+1)+" is empty");

}); 


Use live event handler for dynamically added content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜