This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use jquery to make form fields required on submit?

 
Mark Warner
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have four form fields that I need to make required on submit.

The reason I need jquery to do it is because the four fields only appear if a certain value from a select pulldown is selected. I can get the four fields to show/hide but the required validation is not working at all. Warning I am very new with jquery and Javascript.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Why do you have two ready functions?

And you can shorten this code considerably by using the toggleClass() method.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, as opposed to adding/removing classes, a preferred approach would be to just disable the hidden fields. That way, they are exempt from validation, and also do not participate in the submission.
 
Mark Warner
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And, as opposed to adding/removing classes, a preferred approach would be to just disable the hidden fields. That way, they are exempt from validation, and also do not participate in the submission.


Thanks for the idea about disabling the fields Bear. I think this will allow me to use Dreamweaver to make the hidden dependent fields required and then disable/enable them with jQuery.

However, my dynamic select based on Kaosweaver Dynamic select (http://kaosweaver.com/extensions/details/Dynamic%20Selects) is not working with my jQuery function. Only one or the other will work and that depends which I list higher in the <head> of the document.

The parent dynamic select field is the same field that is compared against in my jQuery function. In the code that is the bank field. Is there a problem with a regular javascript running with jQuery on the same select field?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I would expect that if you run competing libraries on the same control that there will be trouble.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic