Required fields validation

I have a question, on my form, I have a few field that are required is the user is going to register as a paid member.
But I have a radio button where the user selects paid member, or free member. Where if free member is selected I hide
a few fields. But since I'm using the coldfusion required field I would like to know if there is a way to set the required field to NO when the free radio button is selected.

I created this JS but doesn't seen to work.

      document.getElementById("buyerZipCode").required ='no';

any idea?
Who is Participating?
trailblazzyr55Connect With a Mentor Commented:
In this case it sounds like you should do away with the <cfinput> and built in validation and just use javascript validation, this way you have a lot more control over what's going on...

if you post the code we can help modify it to do what you need...
i always (well so i have learnt on here from others) to use script to validate, it will give you more control for example...

<cfif Len(#FORM.example#) LT x>
      alert('you need to enter a number! etc.)


quote > I created this JS but doesn't seen to work.

it won't, the page has already been served by this point i think, the page would need to be refreshed
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

in you're case i would check input on submit if the users has picked paid or free (cfif isdefined etc), if paid is picked check the fields you need to be filled in have got the correct values, if not display a message like in the example above and take them back a page "history.go(-1)"
i knew you were going to say that trailblazzyr55, helping me sooooooooo many times you finally drummed that into me lol.

I only decided to try and answer a few questions in CF based on what I have learnt/remembered from the last few questions you answered for me, hope you don’t mind its all in the learning curve.

Nah, I encourage you to answer questions to help others learning or to solve problems you might have answers to. Experts may debate over questions but in the end it serves to help those asking questions... I don't know everything there is to know about CF, but answering questions and being corrected sometimes helps as much as asking questions... ;o)
EnnioAuthor Commented:
I created my own JS, it gives you more flexibility

Now I can manage what I need to be the required fields.
cool, thanks trailblazzyr55 thats goodto know, anyway  Ennio sorry to highjack the post, back to the question :)

> I created my own JS, it gives you more flexibility

thats what trailblazzyr55 stated to do, what JS did you use?
Try using jQuery simple Form Validation
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.