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

Limit Number of Checkboxes that Can be Checked

Explorer ,
Jun 30, 2010 Jun 30, 2010

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!

958
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
Guest
Jun 30, 2010 Jun 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.

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
Engaged ,
Jul 24, 2010 Jul 24, 2010
LATEST

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

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