views:

1401

answers:

1

hello guys, I'm using Jquery and html and I just ran into an issue with list menu (multiple) validation. The issue is that I cannot(/do not know how to) count the number of selections the user has made. I tried adding ':' at the end of every option value and then split the text into an array, and it did work but then I mess my database.

  var int_country= $('#int_country :selected').text();
  listLength = int_country.split(":");

if (listLength.length > 16){

var i = listLength.length -1;
alert ("You have selected " + i + " countries. \nPlease select 15 or less international countries!");
 $('#int_country').focus();
 return false;
}

Any suggestions how to get around this?

+2  A: 

$('#int_country :selected').length to get the count

redsquare
wow that was easy, thanks a bunch