• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Using jQuery in dynamic table row

 
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following script works wonderfully in .jsp. NaN with message to enter a valid number, displayed inside the text input that is within a table cell.



I need to apply this to a dynamically generated DOM table row. In each of my tests I get NaN, but no message. What's happening to the message?

In the addRow.js I added:



and to the .jsp I tried:


I also tried doing it all in the addRow.js and adding my own message:

 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like you are defining a rule for a single field. So it won't apply to any other. Why are you using a rule at all? Just put required and number as classes on the fields.

I assume that "#ClientPayroll" is the form? (If so, would not ClientPayrollForm be a better id?)
 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(If so, would not ClientPayrollForm be a better id?)

Agreed.

Looks like you are defining a rule for a single field.


I have two input cells on each row that need numeric validation. I was trying to add the validation at the end of the addRow.js.

addRowValidation('Hours_' + uniqueNum, 'Pieces_' + uniqueNum);

I also have some JSTL that I will have to update with the validation code. So I was trying to make it a javascript function.

Just put required and number as classes on the fields.


I've seen other examples that reference applying jQuery to the field class, but I get confused about how this affects my CSS class. Consequently I have looked at jQuery addClass. I'll look in my jQuery book and see if I can get the class thing.

My efforts at the validation function appear to catch the number:required because I get NaN, but it's like the message is going someplace else. I get no errors in Firebug and like most javascript things if I do not get errors, finding the problem is hard. I should have mentioned that I did not do the addRow.js with jQuery. It looks something like this:



 
Howard Watson
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This appears to be working for me.
At the end of the addRow.js:

In the JSP:

reference: http://stackoverflow.com/questions/3839679/use-field-name-variable-in-jquery-validation-rules

I knew there was a problem there I just couldn't figure out how to address it. Also, the NaN is a result of in my row calculations.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic