Jump to content

Multi Select Transfer with count entries


stb74

Recommended Posts

I have a multi select script that allows me to transfer values from one multi select list to another.  But I would like to be able to count the number of entries that I am adding to the second list and display this to a maximum of 11.

 

I also need to display an error if I try and save this and there are less than 11 in the second list box.

 

<script>
    $(document).ready(function() {
   $("#select_left").multiSelect("#select_right", {trigger: "#options_right"});
   $("#select_right").multiSelect("#select_left", {trigger: "#options_left"});
   
   $("#select_left2").multiSelect("#select_right2", {trigger: "#options_right2"});
   $("#select_right2").multiSelect("#select_left2", {trigger: "#options_left2"});
});
</script>

 


<table width="100%" border="0" cellpadding="0">
  <tr>
    <td width="40%">
<select id="select_left" name="players[]" size="20" multiple="multiple">
<? foreach($players as $player): ?>
<option value="<?=$player['ID_PLAYER'];?>">
<?=substr($player['firstname'], 0, 1);?> 
<?=strtoupper($player['lastname']);?>
<? endforeach; ?>
</select>
     <td style="text-align:center; vertical-align:middle;">
      <a id="options_right" href="javascript:void(0);">Add >></a><br/><br/>
      <a id="options_left" href="javascript:void(0);"><< Remove</a>
    </td>
    <td width="40%">
   	<select id="select_right" name="match_players[]" size="20" multiple="multiple">
<? foreach($match_players as $player): ?>
<option value="<?=$player['ID_PLAYER'];?>">
<?=$player['playername'];?> 
<? endforeach; ?>
</select>
<p id="players_selected">
Please pick 11 players from the list who played in this match.
</p>
</td>
  </tr>
</table>
</fieldset>
<?=form_submit('submit', 'Save');?>
<?=form_close();?>

 

I have also played around with this code but it needs me to have the items in the list selected to work.

 


<script type="application/javascript">
$(function() {
var num_players = 0;
$("#select_right").change(function(){
	num_players = 0;

	$("#select_right").children().each(function(){
		if($(this).attr('selected')) { num_players++; }
	});

	$("#players_selected").html('You have selected ' + num_players + ' players.');
});

$("#players_form").submit(function(){
	if(num_players != 11) {
		alert('Please select 11 players, you have currently selected ' + num_players + '.');
		return false;
	}
});
});
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.