jeudi 22 janvier 2015

How to validate table value based on checkbox selected

Following is my table structure:



<tr class="odd">
<td class=" sorting_1">
<input id="clone1042154701" class="fileCheckAll" type="checkbox" name="clone1042154701" checked="">
</td>
<td class="">
<input id="appName1042154701" class="fileAppName invalid" type="text" onblur="validate(this.value,1042154701)" name="appName1042154701">
<div id="error1042154701">
</td>
<tr>
<tr>

<tr class="even">
<td class=" sorting_1">
<input id="clone1042154702" class="fileCheckAll" type="checkbox" name="clone1042154702" checked="">
</td>
<td class="">
<input id="appName1042154702" class="fileAppName invalid" type="text" onblur="validate(this.value,1042154701)" name="appName1042154701">
<div id="error1042154702">
</td>
<tr>
<tr>
.
.
.
and many more rows


On onblur event I am calling a javascript validate function which sets class as "invalid" on error.


Now before form submission I am call a javascript method inside which checks class for error and returns false id error.



if ($("[id^=appName]").hasClass("invalid")) {
alert("Invalid Application name");
return false;
}


The problem that I am facing is that it is validation all the table rows irrespective of whether it is checked via checkbox or not. I need to validate only those row which are checked via checkbox.


Can some please suggest me how to proceed.





Aucun commentaire:

Enregistrer un commentaire