bind a cfselect to a check box

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default bind a cfselect to a check box

    Hi All, is it possible to have a cfselect binded to a checkbox. What I am
    trying to accomplish is the following. I have a cfselect that is populated by
    a query. When a user selects an item from the cfselect dropdown, I want the
    checkbox to be selected for this dropdown listbox. Either actionscript or
    javascript would be ok.

    Thanks in advance

    EdmondsM Guest

  2. Similar Questions and Discussions

    1. Can we bind the values from cfselect to display thoseinto cfinput text boxes.
      Hi, I have a cfselect box which is having values from cfquery. I want to bind those values into few input boxes. I have been trying for so many...
    2. CFSELECT HELP!
      What I am trying to do seems simple but I'm going crazy! I need have a page where I have the user "Select Options" from a drop down box and when...
    3. cfselect options dependent on choice from other cfselect
      I have 2 cfselects. 1st is category, 2nd is sub category. both are populated from database queries, but the options from the sub cat vary based...
    4. Bind cfselect to another cfselects index
      I have been really battling with this problem. I have a normal html form which works with javascript. I have however not been able to get this to...
    5. CF7 BIND CFSELECT to populate a 2nd & 3rd CFSELECT
      Please could some show code of how this is done: CF7 - Flash page Question: How do I bind these cfselect dropdown lists to one another as per the...
  3. #2

    Default Re: bind a cfselect to a check box

    Something like...




    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Bind Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <!--- Dummy query just for demo purposes --->
    <cfscript>
    qTest = QueryNew("");
    hls = ArrayNew(1);
    ids = ArrayNew(1);
    hls[1] = "Headline 1";
    hls[2] = "Headline 2";
    hls[3] = "Headline 3";
    ids[1] = 1;
    ids[2] = 2;
    ids[3] = 3;
    QueryAddColumn(qTest, "Headline", hls);
    QueryAddColumn(qTest, "id", ids);
    </cfscript>

    <!--- User form --->
    <cfform name="myForm">
    <cfselect name="mySelect"
    onChange="javascript:bindToCheckbox(this.selectedI ndex);">
    <option value="" selected>-- Select --</option>
    <cfoutput query="qTest">
    <option value="#qTest.id#">#qTest.Headline#</option>
    </cfoutput>
    </cfselect>
    <br />
    <cfoutput query="qTest">
    <cfinput
    type="checkbox"
    name="myCB"
    value="#qTest.id#">#qTest.Headline#<br />
    </cfoutput>
    </cfform>

    <!--- Form binding function --->
    <script language="javascript">
    function bindToCheckbox(index)
    {
    var target = document.myForm.myCB;
    for (var i=0; i < target.length; i++)
    {
    if (target)
    {
    target[i].checked = false;
    }
    }
    target[index-1].checked = true;
    }
    </script>
    </body>
    </html>

    BSterner Guest

  4. #3

    Default Re: bind a cfselect to a check box

    Thanks for the replay BSterner, it will all me to select a dropdown box item. However, the checkboxes become unselected when others are selected. Did I miss someing??
    EdmondsM Guest

  5. #4

    Default Re: bind a cfselect to a check box

    I assumed you wanted only the checkbox bound to the drop-down menu checked. If
    that's not the case, just lose the js loop below code.

    for (var i=0; i < target.length; i++)
    {
    if (target)
    {
    target.checked = false;
    }
    }

    Also, get rid of the "if (target)" conditional check. So, you're final code
    would look like.

    <!--- Form binding function --->
    <script language="javascript">
    function bindToCheckbox(index)
    {
    document.myForm.myCB[index-1].checked = true;
    }
    </script>

    Make sense?

    for (var i=0; i < target.length; i++)
    {
    if (target)
    {
    target[i].checked = false;
    }
    }

    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139