• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaScript Validation for data in HTML Tables

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Andres, I will take a look at the article!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic