Skip to main content
Participating Frequently
July 28, 2008
Question

How would I add a conditional checkbox to an input field?

  • July 28, 2008
  • 5 replies
  • 1125 views
I am looking to add a conditional checkbox to a CFINPUT field. When the box is checked, I want it to either grey out, or remove the cfinput field frm the screen. I am unfamiliar with how checkboxes work, so could anyone provide some sample code for how to go about this? Here is essentially how i want it to work:

<checkbox>

if unchecked,
make cfinput field visible and usable
if checked
get rid of the cfinput field

Thanks for any help.
Nick Butler

    This topic has been closed for replies.

    5 replies

    Participating Frequently
    July 29, 2008
    Ok, I am taking another apporoach to this prob. Wrather than making an actionscript function, I am trying to handle this with CFIF. Escentially I want the HireDate input field to become usable when I check the check box. When I run this however, I am getting a "Variable ENABLEHIDE is undefined". Could someone help me out?

    <cfinput type="checkbox" name="enablehide" label="No Hire Date" value="1"/>

    <cfif enablehide NEQ 1>
    <cfformgroup type="horizontal" visible="yes" enabled="yes" style="marginLeft:-74;" >
    <cfinput type="datefield" name="HireDate" label="Hire Date:" width="91" bind="{contactList.selectedItem.HireDate}" onchange="UpdateSelect(HireDate);"/>

    </cfformgroup>
    </cfif>
    Inspiring
    July 29, 2008
    quote:

    Originally posted by: NickoSwimmer
    Ok, I am taking another apporoach to this prob. Wrather than making an actionscript function, I am trying to handle this with CFIF.

    Slight problem. Cold Fusion runs on the server and you want client side programming.
    Participating Frequently
    July 29, 2008
    I tried searchign for "actionscript toggle enabled" but could not find anything. Can anyone help me out? Thanks.
    Participating Frequently
    July 29, 2008
    Conditional checkbox is very useful in programs.
    For music http://mp3bravo.com
    Inspiring
    July 28, 2008
    You're using flash forms? Try that google search again but with actionscript instead of javascript.
    Inspiring
    July 28, 2008
    google "javascript toggle enabled" and you should find some code samples.
    Participating Frequently
    July 28, 2008
    Ok, I found a good javascript code snippet for toggleing an entry field.

    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script type="text/javascript">
    function toggle(){
    var args=toggle.arguments, els=typeof args[0]=='object'? args[0].elements : document.forms[args[0]].elements;
    for (var i = els.length-1; i > -1; --i)
    for (var j = args.length-2; j > 0; --j)
    if(els .name==args)
    els
    .disabled=args[args.length-1];
    }
    toggle.init=function(){
    for (var f=document.forms, i = f.length-1; i > -1; --i)
    for (var e=f .elements, j = e.length-1; j > -1; --j)
    if(e.className&&/disabled/.test(e.className))
    e.disabled=true;
    };
    </script>
    </head>
    <body>
    <form name="test" action="#">
    <div>
    <input type="checkbox" onclick="toggle('test', 'bob', !this.checked);">
    <input class="some disabled" type="text" name="bob">
    </div>
    </form>
    <script type="text/javascript">
    toggle.init();
    </script>


    While the code works great if I run it in a new .cfm page, when I enter it into my main code, I get an error saying: "there is no method with the name 'toggle'"

    I have to modify my code obvisly, and here is what I have so far:

    <cfinput type="checkbox" name="enablehide" label="No Hire Date" onclick = "toggle('HireDate', !this.checked);" />

    Is there anyway to get the javascript function "toggle" to work with my CF code? Also, I think the majority of my code is using Action Script (is this similar to javascript?) for action operations.

    Thanks again for any help!
    Nick Butler