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

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

New Here ,
Jul 28, 2008 Jul 28, 2008
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

1.0K
Translate
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 ,
Jul 28, 2008 Jul 28, 2008
google "javascript toggle enabled" and you should find some code samples.
Translate
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
New Here ,
Jul 28, 2008 Jul 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
Translate
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 ,
Jul 28, 2008 Jul 28, 2008
You're using flash forms? Try that google search again but with actionscript instead of javascript.
Translate
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
Community Beginner ,
Jul 28, 2008 Jul 28, 2008
Conditional checkbox is very useful in programs.
For music http://mp3bravo.com
Translate
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
New Here ,
Jul 29, 2008 Jul 29, 2008
I tried searchign for "actionscript toggle enabled" but could not find anything. Can anyone help me out? Thanks.
Translate
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
New Here ,
Jul 29, 2008 Jul 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>
Translate
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 ,
Jul 29, 2008 Jul 29, 2008
LATEST
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.
Translate
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