Hi, I nedd a Validation of the columns and rows in javascript . I have two textboxes as Year and No. I have to do a validation on based on the year and number combination. which i have done but this validation has to be done for all the rows. first the year should be selected and checked whether it is equal to 1982 then it should read coloumn respective to it. llr it should read for 2 nd row year field the number value...soon. Please help....need urgently this code....
>>i have done but this validation has to be done for all the rows If you have done it for one, why not repeat it for the rest? Post the current code; you will get better replies. This JavaScript Form Validation script might be useful.
well you can assign all the fields with same class nam and then loop through all the input fields and validate them
Try this sample code, i think it helps you: <head> <script> function CheckAndSubmit () { var table = document.getElementById ("myTable"); var inputs = table.getElementsByTagName ("input"); for (var i = 0; i < inputs.length; i+=2) { var yearInput = inputs[i]; var numberInput = inputs[i+1]; if (yearInput.value == "1982") { if (numberInput.value > 10) { alert ("Invalid number in the " + (i/2 + 1) + ". row!"); return false; } } } return true; } </script> </head> <body> <form method="post" action="#URL#" onsubmit="return CheckAndSubmit ()"> <table id="myTable"> <tr> <td>Year: <input type="text" value="1985" /></td> <td>Number: <input type="text" value="5" /></td> </tr> <tr> <td>Year: <input type="text" value="1982" /></td> <td>Number: <input type="text" value="9" /></td> </tr> <tr> <td>Year: <input type="text" value="1982" /></td> <td>Number: <input type="text" value="11" /></td> </tr> </table> <input type="submit" value="Send" /> </form> </body> Code (markup): For further details, visit the following sites: onsubmit event, getElementsByTagName method, table object.
Thks for the reply the code is working for the html which u have send .but var inputs = table.getElementsByTagName ("input"); my textfield value is a struts 2 input which will be declared with the <s:textfields> tag how to use this tag in the getElementsByTagName ? and my table alery have a class="xyz" which is the CSS so unable to use both css and Id in table tag i.e. <table id="mytable" class="xyz">.. so pls. help