Check dynamically added textbox

In the code below, how to check for null values ​​only for dynamically added textbox ie, r_score1, r_score2 .........

  <script>
   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();" />

      

+2


a source to share


3 answers


Give the text fields a class name and use a class selector



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

      

+1


a source


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

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

}); 

      



0


a source


Use a live event handler for dynamically added content.

0


a source







All Articles