• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing <cfinput> REQUIRED attribute

Community Beginner ,
Aug 01, 2006 Aug 01, 2006

Copy link to clipboard

Copied

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==false){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
TOPICS
Advanced techniques

Views

450

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 01, 2006 Aug 01, 2006

Copy link to clipboard

Copied

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
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 01, 2006 Aug 01, 2006

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation