6 Replies Latest reply: Dec 28, 2010 5:44 AM by Dan Bracuk RSS

    Hiding Required Information Based on Form Input Information

    OgreOne Community Member

      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

        • 1. Re: Hiding Required Information Based on Form Input Information
          Dan Bracuk Community Member

          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.

          • 2. Re: Hiding Required Information Based on Form Input Information
            Dan Bracuk Community Member

            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.

            • 3. Re: Hiding Required Information Based on Form Input Information
              OgreOne Community Member

              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.

              • 4. Re: Hiding Required Information Based on Form Input Information
                Adam Cameron. Community Member
                I really dislike JavaScript and try not to program with it unless a client really "needs" it.

                 

                Hang on. You said you're using JQuery and <cfform>.  Both of which use JavaScript "heavily". All JQuery is is a JS library: it's pure JavaScript!

                 

                Too bad Coldfusion can't build in a way to do this kind of conditional on the fly.

                 

                 

                 

                If you need to do something client-side then you need to use a client-side technology... JS or Flash, basically.

                 

                CF runs on the CF server and has (and can have ~) no interaction with the client browser.

                 

                I think you need to sit back and do some reading and understand how all the technology components fit together in the HTTP request/response lifecycle, because you seem to be labouring under some misconceptions, based on the wording of your post.

                 

                --

                Adam

                • 5. Re: Hiding Required Information Based on Form Input Information
                  OgreOne Community Member

                  No, I understand that both rely heavily on JS.  I am not that naive.  I just would thing that maybe the programmers would come up with an extension or something to help automate the process a little more.  I just don't see how me being the only one, or few who would use this.  When it comes to jQuery/JavaScript, a lot of us work with libraries or already coded examples that we tweak (especially those who are more design-oriented, less programming). Maybe Adobe/Macromedia has done a disservice in helping us out too much.

                   

                  Anyway, no you are right, JavaScript is required.  I just don't want to program THAT much for one or two fields so I think I will try and go the Custom Error Page method and see what I can do there.

                   

                  Thanks all.  I love Adobe forums because you always get an answer.

                  • 6. Re: Hiding Required Information Based on Form Input Information
                    Dan Bracuk Community Member

                    Regarding, "When it comes to jQuery/JavaScript, a lot of us work with libraries or  already coded examples that we tweak (especially those who are more  design-oriented, less programming)."

                     

                    I'm a programmer and I do that too.  Fortunately there are lot's of coded examples on the internet and good search engines with which to find them.