[jQuery] Bindind keydown function to a form - submit on keydown (value change)

2010-01-20 Thread Mircea
Hi,
I am trying to make a form to run a function on keyup, keydown.
The markup is:

select id=family
option value=Georgia label=GeorgiaGeorgia/option
option value=Times New Roman label=Times New RomanTimes New
Roman/option
option value=HelveticaNeue-Light label=Helvetica Neue
LightHelvetica Neue Light/option
/select

I made a function that change the font-family on click:

script type=text/javascript
$(document).ready(function(){

$('#family').click(function() {
 value = $(this).val();
 $('.cica').css('font-family', value)
 });
});

//capture the down key
$(#family).bind(keydown, function(e) {
if (e.keyCode == 40) {
value = $(this).val();
$('#family').css('font-family', value)
return false; //prevent default behavior
}
});

/script


I am trying to bind a keydown to this form so when I press Down key
the form change its value and execute the function - change the font-
family.
It looks that my bind keydown does nothing. What should I change here?

Thank you.


Re: [jQuery] Bindind keydown function to a form - submit on keydown (value change)

2010-01-20 Thread Nathan Klatt
function setFamily() {
  $('#family').css('font-family', $('#family :selected').val());
}
$().ready(function() {
  setFamily();
  $('#family').bind(change keypress, setFamily);
}

As a bonus, this will work if they press the first letter of the
option they're selecting - it's all good. :)

Nathan