[jQuery] Re: Filtering a select list

2009-06-30 Thread shaded


@mkmanning

many thanks!! All i needed to do is add a text box with a keyup event
and change the regular expression to match everything and not just the
first beginning of the last name.

Here is the solution in case anyone else is  searching. Thanks
again.

html
head
script src=http://code.jquery.com/jquery-latest.js;/script
script
  $(document).ready(function(){
//cache the original select and options
var selList = $('select'), opts = selList.find('option');

//filters by first letter of last name as option text
function filterList(ltr){
selList.empty();
if(ltr==='All' || ltr==''){
selList.append(opts);
return;
}
   // var re = new RegExp(^+ltr,i);//, newopts = '';
var re = new RegExp(ltr,i);



$.each($.grep(opts,function(o,i){return re.test($
(o).text());}),
function(){
selList.append(this);
});
}

$('#search').keyup(function(){
filterList( $('#search').val() );
});

});
  /script


/head

body

!--  spanAll/span spanBe/span ... spanW/span  --
input type=text id=search  /input
select size=6
optionBellucci, Monica/option
optionBernhardt, Daniel/option
optionChou, Collin/option
optionFishburne, Laurence/option
optionGaye, Nona/option
optionHulme, Lachy/option
optionLees, Nathaniel/option
optionLennix, Harry J./option
optionMcColm, Matt/option
optionMoss, Carrie-Anne/option
optionO'Reilly, Genevieve/option
optionPerrineau, Harold Jr./option
optionPinkett Smith, Jada/option
optionRayment, Adrian/option
optionRayment, Neil/option
optionReeves, Keanu/option
optionSpence, Bruce/option
optionWeaving, Hugo/option
optionWilson, Lambert/option
optionWong, Anthony/option
/select
/body
/html


[jQuery] Re: Filtering a select list

2009-06-26 Thread Alexandre Magno

Hello,

With http://www.texotela.co.uk/code/jquery/select/

you can manipulate selects easily, not so directly like the one you
show that it's great...

Alexandre Magno
Interface Developer
http://blog.alexandremagno.net

On Jun 26, 12:29 pm, shaded dar...@eztransition.com wrote:
 here is a non jquery solution to what i'm looking for.

 http://www.barelyfitz.com/projects/filterlist/index.php/1

 Does anyone know of jquery plugin to do the same or maybe if its easy,
 some quick source code?

 thanks


[jQuery] Re: Filtering a select list

2009-06-26 Thread mkmanning

Some quick source code:

HTML:
spanAll/span spanB/span ... spanW/span
select size=6
optionBellucci, Monica/option
optionBernhardt, Daniel/option
optionChou, Collin/option
optionFishburne, Laurence/option
optionGaye, Nona/option
optionHulme, Lachy/option
optionLees, Nathaniel/option
optionLennix, Harry J./option
optionMcColm, Matt/option
optionMoss, Carrie-Anne/option
optionO'Reilly, Genevieve/option
optionPerrineau, Harold Jr./option
optionPinkett Smith, Jada/option
optionRayment, Adrian/option
optionRayment, Neil/option
optionReeves, Keanu/option
optionSpence, Bruce/option
optionWeaving, Hugo/option
optionWilson, Lambert/option
optionWong, Anthony/option
/select

JS:
$(document).ready(function(){
//cache the original select and options
var selList = $('select'), opts = selList.find('option');

//filters by first letter of last name as option text
function filterList(ltr){
selList.empty();
if(ltr==='All'){
selList.append(opts);
return;
}
var re = new RegExp(^+ltr,i), newopts = '';
$.each($.grep(opts,function(o,i){return re.test($(o).text
());}),function(){
selList.append(this);
});
}

$('span').click(function(){
filterList( $(this).text() );
});
});

Maybe that will give you someplace to start.

On Jun 26, 8:29 am, shaded dar...@eztransition.com wrote:
 here is a non jquery solution to what i'm looking for.

 http://www.barelyfitz.com/projects/filterlist/index.php/1

 Does anyone know of jquery plugin to do the same or maybe if its easy,
 some quick source code?

 thanks