I'm pretty new to Jquery and the coding side of things in general, so please excuse my noobishness. I'm still learning! Anyway, my problem is that I have some radio buttons on a form that depending on which option is picked, a text input field is displayed. I want to have the radio buttons required as well as the text input field if it's shown. I can't figure out how to set up the validation for that. If someone could post an example of how I might do this, I'd be MOST grateful! I'll post some code-snippets below to help clarify things.
Radio buttons and Show/Hide div with text field:
<label for="delivery_method">*Delivery or In-Store Pickup?</label><br />
What I want to do:
Both "delivery_method" radio buttons made required fields, forcing the user to select a delivery method before form can be submitted successfully.
If the user selects delivery for their option, "delivery_address" field is revealed and also made a required field (since it would do us no good to know a user wants their order delivered but we don't know where to ship to!)
required: "This field is required if you selected Custom Size above."
required: "This field is required if you selected Delivery above."
The bits about custom_size is for a select menu where if the user selects "custom" for the value, then the final_size text field is made required.
I want to do the same thing with delivery_address. Here I'm attempting to tell the validate script to check delivery_method and see if it's value is "Delivery", if it is... then make delivery_address a required field and use a specific error message if nothing gets entered.
Upon testing, the above script merely makes delivery_address required REGARDLESS of what's checked. So if a user opts to pick in-store pick up for delivery_method, the delivery_address field remains hidden but is still required... essentially blocking form submission.
I know what I have is wrong, probably something with syntax. What am I doing wrong?
I also realized that by not having unique id's for my radio buttons that this was confusing things in the code. So I gave them unique id's. The delivery option was changed to "delivery_method_del", as you can see above in blue.
Leave a comment on c.reeves's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic