2 Replies Latest reply on Aug 1, 2006 11:39 AM by Dan Bracuk

    Changing <cfinput> REQUIRED attribute

    Natesac
      Hey kids... Here's what I'm trying to do...

      I have a form that has two required fields, and then a checkbox after those which, if checked, disables the first two fields. However, when I try to submit my form, I still get the Alert message based on the requirements of the fields. Now, I tried doing this, which I thought may work in the same fashion as changing the disabled value:

      <cfquery name="sourcekeys" datasource="momlink">
      Select Adkey, Addate, AdProd
      From Adcosts
      </cfquery>

      <cfselect name="AdPrefix" display="AdPrefix" query="getPrefixes" value="AdPrefix" class="style14" style="width:75px;" required="yes" message="Please select a Source Key Prefix"></cfselect>

      <cfinput type="text" class="style14" name="AdSuffix" value="" required="yes" maxlength="4" style="width:20px;" message="Please enter the 3 or 4 digit sequence that correponds to the Source Key" validate="integer">

       or Outbound 

      <input type="checkbox" class="style14" name="Outbound" value="Outbound" onClick="if(document.checkoutform.Outbound.checked==true){document.checkoutform.AdPrefix. disabled=true;document.checkoutform.AdSuffix.disabled=true;document.checkoutform.AdPrefix. required=no;
      document.checkoutform.AdSuffix.required=no;};if(document.checkoutform.Outbound.checked==fa lse){document.checkoutform.AdPrefix.disabled=false;document.checkoutform.AdSuffix.disabled =false;};"
      <cfif MomCustnumCheck eq False>disabled</cfif>>

      Any thoughts as to why I'm able to change the value of DISABLED in my cfinputs, and not the REQUIRED attribute?

      Many thanks, oh gurus of the fusion.

      -Nathan
        • 1. Re: Changing &lt;cfinput&gt; REQUIRED attribute
          Level 7
          Because Disabled is part of the standard for the <input...> tag that a
          <cfinput...> tag is turned into by the ColdFusion engine in the response
          that is sent to the client.

          By the time your javascript running on the client is trying to access
          it, it is long gone and done with. This is the standard separation of
          what happens on the server and what happens on the client and they don't
          mix together.

          What that required attribute is doing is creating some automagic
          javascript functions. If you look at your source you should be able to
          see what was created and figure out what you may be able to change. I
          would guess some kind of on_blur or on_submit event.


          Natesac wrote:
          > Hey kids... Here's what I'm trying to do...
          >
          > I have a form that has two required fields, and then a checkbox after those
          > which, if checked, disables the first two fields. However, when I try to
          > submit my form, I still get the Alert message based on the requirements of the
          > fields. Now, I tried doing this, which I thought may work in the same fashion
          > as changing the disabled value:
          >
          > <cfquery name="sourcekeys" datasource="momlink">
          > Select Adkey, Addate, AdProd
          > From Adcosts
          > </cfquery>
          >
          > <cfselect name="AdPrefix" display="AdPrefix" query="getPrefixes"
          > value="AdPrefix" class="style14" style="width:75px;" required="yes"
          > message="Please select a Source Key Prefix"></cfselect>
          >
          > <cfinput type="text" class="style14" name="AdSuffix" value="" required="yes"
          > maxlength="4" style="width:20px;" message="Please enter the 3 or 4 digit
          > sequence that correponds to the Source Key" validate="integer">
          >
          >  or Outbound 
          >
          > <input type="checkbox" class="style14" name="Outbound" value="Outbound"
          > onClick="if(document.checkoutform.Outbound.checked==true){document.checkoutform.
          > AdPrefix.disabled=true;document.checkoutform.AdSuffix.disabled=true;document.che
          > ckoutform.AdPrefix.required='no';
          >
          > document.checkoutform.AdSuffix.required='no';};if(document.checkoutform.Outbound
          > .checked==false){document.checkoutform.AdPrefix.disabled=false;document.checkout
          > form.AdSuffix.disabled=false;};"
          > <cfif MomCustnumCheck eq False>disabled</cfif>>
          >
          > Any thoughts as to why I'm able to change the value of DISABLED in my
          > cfinputs, and not the REQUIRED attribute?
          >
          > Many thanks, oh gurus of the fusion.
          >
          > -Nathan
          >
          • 2. Re: Changing &lt;cfinput&gt; REQUIRED attribute
            Dan Bracuk Level 5
            It sounds like the two fields are only required when the checkbox is unchecked. That being the case, the required attribute is not appropriate, you have to write your own javascript.

            If javascript is not your strong suit, I recommend the book, Teach Yourself Javascript in 24 Hours, that's how I learned it.