aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes how to use jquery to make form fields required on submit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to use jquery to make form fields required on submit?" Watch "how to use jquery to make form fields required on submit?" New topic
Author

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

Mark Warner
Greenhorn

Joined: Aug 12, 2010
Posts: 10
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

Joined: Jan 10, 2002
Posts: 61220
    
  66

Check out the jQuery Validation Plugin


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61220
    
  66

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

Joined: Jan 10, 2002
Posts: 61220
    
  66

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

Joined: Aug 12, 2010
Posts: 10
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

Joined: Jan 10, 2002
Posts: 61220
    
  66

Yeah, I would expect that if you run competing libraries on the same control that there will be trouble.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use jquery to make form fields required on submit?