stb74 Posted March 17, 2008 Share Posted March 17, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/96567-multi-select-transfer-with-count-entries/ Share on other sites More sharing options...
Psycho Posted March 18, 2008 Share Posted March 18, 2008 Hmmm, there seems to be something missing. I have pasted the code above into an HTML page (replacing the PHP loops with test OPTION entries) and it doesn't work for me. Can you post a working example? Quote Link to comment https://forums.phpfreaks.com/topic/96567-multi-select-transfer-with-count-entries/#findComment-495042 Share on other sites More sharing options...
stb74 Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks for the reply and effort. Got it sorted thanks. Quote Link to comment https://forums.phpfreaks.com/topic/96567-multi-select-transfer-with-count-entries/#findComment-495246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.