views:

63

answers:

2

In the below code,the textaraes are generated dynamically ,now how to get these values for validations in valid() function..

  <script>
   function valid()
    {
         //get all textarea vales for validation
    }


  function add(col_det)
  {
 var row = '<tr>';
row += '<td>';
row += '<textarea rows = "8" cols = "8" class = "input" WRAP id="row_details'+r_count+'" name ="row_details'+r_count+'"></textarea>';
row += '</td>';
for (var i=0;i<col_det.length;i++)
{
   row += '<td> <div id = "div_content_bold"> <textarea rows = "2" cols = "8" class = "input" id="c_details'+c_count+'" name="col_details'+l_count+'" WRAP ></textarea> </div> </td>';

 }
 row += '<td></td>';
 row += '</tr>';
return row; 
 }



 $(document).ready(function() {
 var cnt = '<input type="text" name="title" id="title" ><br><br>';
 cnt += '<table cellspacing="0" cellpadding="0" border="1" width="100%" id="l_table">';
 cnt += '<tr>';
 cnt += '<th width="30%">Category</th>';
 cnt +=  headers(col_data); 
 cnt += '<th width="10%">Grade obtained</th>';
 cnt += '</tr>';
 for(var i=0;i<criteria;i++)
 {
   cnt += add(col_data,i);
 }
 cnt += '</table>';
 $('#content').append(cnt);

 });
</script>
<form action="create/" method="post" name="aa">
<div id="content"></div>
<table>
 <tr><td>
 <input type="submit" value="Save" id="Save" onclick="javascript:var   ret=validate(row_c,c_count);return ret;"/></td></tr>

Thanks....

+2  A: 

You can loop over all the textareas on the page and validate the contents by using .each

$('textarea').each(function(i){ // do validation here using $(this).val() });

Yisroel
Are you sure since i have this generated dynamically even if i loop over using normal javascript.i do not get the values..
Hulk
I just tested this and it worked for me. I was using chrome fyi so not sure about all browsers.
ryanulit
A: 

If they are assigned dynamically, add classes so you can select them.

 $('textarea.generated').each (function(i) { });
SHiNKiROU