Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript Validation for data in HTML Tables

 
Radu Zaharia
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my project I have to dynamically create a table which consists of a variable number of rows.
Each row has an OK button, a Cancel button, a select, and a number of text controls.
I initially load the table from a database, and then I must be able to add, edit or delete rows from the table (and then from the database).
Prior to submitting the new/modified data to the database, I must validate the data in the row I have added/modified (some of the text controls must contain dates, others must contain numbers, and so on).
In one version of the project, I made the validation on the server side, but in this case, if the validation does not succeed, I must reload the page from the database and I loose the changes made by the user on the modified row, which the client finds unacceptable.
So I think I have to make a client side validation using JavaScript. When for example I press the OK button on the row number 3 (from a total of 10 rows) the task I have is this:
1)determine the modified row is row 3;
2)call the JavaScript validation function, which has to validate the text in all the controls from row 3;
So my questions are:
1)how can I determine I pressed the OK button of the row 3? (all the buttons have the same name=�ok�)
2)how can I access the text in the various text controls? (each text control belongs to an array, so for example the names of the text controls on row 3 are: �dataIn_2�, �dataOut_2�, �id_2�, and so on)
Thanks,
Soto
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Soto Mayor:
...
In one version of the project, I made the validation on the server side, but in this case, if the validation does not succeed, I must reload the page from the database and I loose the changes made by the user on the modified row, which the client finds unacceptable.

This is based from what I understood..
Can't you use a JavaBean component that *maps* to your fields? if your validation fails in the serverside, you forward to a JSP and it'll make use of the bean, without loosing any information.
this is an example.

So I think I have to make a client side validation using JavaScript.

Quick and simple solution. But, what happens if your client disables JavaScript? you are in trouble... you are not solving the problem, you're covering it ;-)

HTH
 
Radu Zaharia
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Andres, I will take a look at the article!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to use javascript, you can make each row a separate form. You still should do some error checking on the server though.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic