user2472480
user2472480

Reputation: 125

Getting values from select form with JQuery not working

Right now I have this code:

  $(".categories").change(function(){
var target = $('.categories option:selected').val();


  if(target == "Career")
      $(".subcat").css( "display","inherit" );
  else if(target == "Life Style")
      $(".subcat2").css( "display","inherit" );
  else if(target == "Do It Yourself")
      $(".subcat3").css( "display","inherit" );
  else if (target == "Other")
      $(".subcat4").css( "display","inherit" );

});

however when I choose whatever category it only return the value as being "Career", and not anything else, even though I select other options. How do I fix it?

Upvotes: 1

Views: 23

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

Try,

var target = $(this).val();

instead of

var target = $('.categories option:selected').val();

Upvotes: 1

Related Questions