Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Limited Checkbox Selection


  • Nick Watson
    Participant

    @nickbwatson

    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)

  • D Cartwright
    Participant

    @aekeron

    Incredibly easy with javascript.

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


    Nick Watson
    Participant

    @nickbwatson

    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?


    Nick Watson
    Participant

    @nickbwatson

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


    noyzen
    Participant

    @noyzen

    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

    @heathernew

    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

    @heathernew

    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

    @heathernew

    <?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

    @shanebp

    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

    @shanebp

    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