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
https://forums.phpfreaks.com/topic/96567-multi-select-transfer-with-count-entries/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.