Skip to main content
Known Participant
December 26, 2010
Answered

Hiding Required Information Based on Form Input Information

  • December 26, 2010
  • 1 reply
  • 1052 views

Okay, I am trying to create a form and using jQuery, I have hidden a list of required form fields (ie. <cfinput...required="yes") if the user chooses a cetain radio button/checkbox. The problem is that when that portion of the form is hidden, it, of course does not "hide" the need for the required fields.

I have tried using:

<input name"form_field".... />

<cfif #form.form_field# NEQ "" AND #form.form_field NEQ " ">

   <cfinput....required="yes" />

</cfif>

but that does not work, so I thought maybe using a 'isDefined' arguement but it does not recognize that I had enterd anything into the form.form_field input.

Any thoughts?  I am sure someone has tried something similar.  I cannot be the only idiot out there

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    You have to use javascript, not coldfusion code to accomplish this.  One approach you might try is to create a couple of variables.  One will be an empty string and the other will be the required form fields.  Then you use those variables for the value of a div or span, based on the radio button selection.

    I've done this type of thing poorly a few times, but I remember that BKBK once posted something on these forums that seemed like a really good way to go about it.

    1 reply

    Dan_BracukCorrect answer
    Inspiring
    December 27, 2010

    You have to use javascript, not coldfusion code to accomplish this.  One approach you might try is to create a couple of variables.  One will be an empty string and the other will be the required form fields.  Then you use those variables for the value of a div or span, based on the radio button selection.

    I've done this type of thing poorly a few times, but I remember that BKBK once posted something on these forums that seemed like a really good way to go about it.

    Inspiring
    December 27, 2010

    Actually, one of my methods wasn't all that bad.  It just works differently in firefox than in IE.  Don't know about other OS/browsers.

    Use cfsavecontent to create a coldfusion variable with your required form fields.

    Use toScript() to send that variable to javascript.

    Use innerHTML to change the value of your div.

    OgreOneAuthor
    Known Participant
    December 28, 2010

    Thanks for the comments.  Guess it is hopless then.  I really dislike JavaScript and try not to program with it unless a client really "needs" it.  Too bad Coldfusion can't build in a way to do this kind of conditional on the fly.

    Thanks anyway.