jmg
jmg

Reputation: 19

how to change values of a dropdown on key press using jquery

i need to change values of a "Focused" dropdown on keypress using jquery.

i need,

  1. how i get a foucsed drop down or how i can check whether the drop down has focus.
  2. how to change this drop down values in key press like 1,2,3 etc. using JQUERY.

thanks in advance.

Upvotes: 1

Views: 1734

Answers (1)

Richard Calahan
Richard Calahan

Reputation: 166

To see if object is selected:

if($(".foo").is(':focus')){

   // do something

}

To change values on keypress:

$(".foo").bind("keypress", function(e){

   $(this).attr('value', 'bar'); 

})

Though not sure what you mean by changing the values of a drop down, or why you'd want to do that.

Upvotes: 1

Related Questions