Monday, April 27, 2009

[jQuery] Re: jQuery next() to find <select><option>

hi,


       $(document).keydown (function(e) {
               if (e.keyCode == 37)
                       if(n == $('select option:selected').prev('option').val()
)
                               location.href = n;
               if (e.keyCode == 39)
                       if(n == $('select option:selected').next('option').val())
                               location.href = n;
       });

If i get you right, this should do the trick?


On Mon, Apr 27, 2009 at 10:30 PM, dimitre <dimitre79@gmail.com> wrote:

Hello I am using jQuery next() and prev() to navigate inside
<select><option> tags.
problem is I am using <optgroup> too and can't find a way to make it
work


ex:
<select>
                       <optgroup label="Motion">
                       <option value="/m01/" >001</option>
                       <option value="/m02/" >002</option>
                       <option value="/m03/" selected>003</option>
                       <optgroup label="illustration">
                       <option value="/illustration01/" >illustration01</option>
                       <option value="/illustration02/" >illustration02</option>
</select>

       $(document).keydown (function(e) {
               if (e.keyCode == 37)
                       if(n = $('select option:selected').prev().val())
                               location.href = n;
               if (e.keyCode == 39)
                       if(n = $('select option:selected').next().val())
                               location.href = n;
       });

No comments:

Post a Comment