Skip to main content
Inspiring
June 30, 2010
Frage

Limit Number of Checkboxes that Can be Checked

  • June 30, 2010
  • 2 Antworten
  • 1016 Ansichten

I'm using Ray Camden's "Soundings" and I need to limit the number of answer checkboxes that can be checked in a survey to 5 and I need some help with the code. I've tried some JavaScript solutions with no working results.

<cfoutput>
<p>
<div class="answers">
    <cfset type="checkbox">
    <cfloop query="answers">
  <input type="#type#" name="question#attributes.step#" id="question#attributes.step#_#id#" value="#id#" <cfif listFindNoCase(attributes.answer,id)>checked</cfif>><label for="question#attributes.step#_#id#">#answer#</label><br>
  </cfloop>
  </div>
</p>
</cfoutput>

Thanks!

    Dieses Thema wurde für Antworten geschlossen.

    2 Antworten

    Inspiring
    July 24, 2010

    Hello IraMSN,

    If the option provided by RichinternetFrank does not work for you. Below

    is a link to a javascript solution that might work for you as an alternative.

    http://javascript.internet.com/forms/limit-boxes.html

    Leonard B

    June 30, 2010

    I think Javascript should do the trick.

    I don't know the soundings app, but if "step" is the same value for all the checkboxes inside the loop then add an onClick event to the input tag. The onClick event then calls a javascript function. The javascript function expects a value with that you can identify the group of checkboxes (probably "step").

    Inside the javascript function use getElementsByName() to get the group of checkboxes, loop through them and check every single element if it's checked. Count the checked elements and if the result is greater than five show a message box and uncheck the last checked box.