Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Limited Checkbox Selection

  • @nickbwatson

    Participant

    I was wondering if it was possible to set a limit on the checkbox field (for profile fields).

    So lets say I have “Select 2 of your favorite colors”
    Red
    Green
    Blue
    Yellow

    And then when they select red and blue, and try to select yellow a message says “Please only select 2” And it doesn’t allow them to check anymore.

Viewing 9 replies - 1 through 9 (of 9 total)
  • @aekeron

    Participant

    Incredibly easy with javascript.

    First google result: http://www.webmasterworld.com/forum91/1560.htm

    @nickbwatson

    Participant

    I did see that, but how can I do that with the way buddypress is set up? What files do I need to edit basically?

    @nickbwatson

    Participant

    Does anyone know how to implement this into the profile fields on buddypress?

    @noyzen

    Participant

    i have same need.
    is there any plugin to make more advanced profile fields??

    another thing i need is when people select for example country from a combobox next combobox load cities of that country so he can select city of country.

    any plugins?

    @heathernew

    Participant

    Any luck with this yet Nick? I’m also wanting to do the same thing, javascript would be great with a little more instruction

    @heathernew

    Participant

    I found a way to hide the list if they didn’t choose the suggested number but ideally I would like it to give them a pop up notification that you can only select 5 instead of just being listed in the description under the box.

    @heathernew

    Participant
    <?php if ( count($expertise) <= 5 ) : ?>
    	<div class="expertise">
    		<p><strong>Areas of Expertise:</strong></p>
    		ul>
    			<?php $track <= 5; foreach ( $expertise as $area ) : $track++; ?>
    				<li><?php echo $area; ?></li>
    				
    		<?php if ( $track== ceil( count($expertise) / 3 ) ) : $track = 0; ?>
    		/ul>
    		ul>
    		<?php endif; ?> 
    				
    			<?php endforeach; ?>
    		/ul>
    	</div>
    <?php endif; ?>

    This is located in the member-header.php

    @shanebp

    Moderator

    javascript:

    function checkboxlimit(checkgroup, limit){
    	for (var i=0; i<checkgroup.length; i++){
    		checkgroup[i].onclick=function(){
    		var checkedcount=0
    		for (var i=0; i<checkgroup.length; i++)
    			checkedcount+=(checkgroup[i].checked)? 1 : 0
    		if (checkedcount>limit){
    			alert("You can select a maximum of "+limit+" boxes.")
    			this.checked=false
    			}
    		}
    	}
    }		
    checkboxlimit(document.forms.your_form_name_or_id['field_name[]'], 5);

    @shanebp

    Moderator

    format got messed up, so look here for a non-jQuery approach: http://pastebin.com/0afNVh3e

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Limited Checkbox Selection’ is closed to new replies.
Skip to toolbar