I've been searching around how to add jQuery to Drupal 7, but i couldn't make it work. Here is my steps:
Step 1: I create a javascript file and put into my module under js directory.
Step 2: I added the file to my module .info
scripts[] = js/xxx.js
Step 3: The contents of the xxx.js
(function ($)
{
Drupal.behaviors.mymodule =
{
attach: function(context, settings) {
$("#edit-field_a",context).change(function(){
currentValue = $(this).val();
alert(currentValue); // no fire at all
if(currentValue == 'a')
{
$('#edit-field_b').val('All');
}
}
}
};
})(jQuery);
All the fields are on exposed filter form. I wish to do something like the value of the field_b select list changed based on field_a select list.
What did i miss? Is my jQuery correct?
Updates: Previous js is wrong, corrected here.
(function ($)
{
Drupal.behaviors.mymodule =
{
attach: function(context, settings) {
$("#edit-field_a",context).change(function(){
currentValue = $(this).val();
alert(currentValue); // no fire at all
if(currentValue == 'a')
{
$('#edit-field_b').val('All');
}
});
}
}
})(jQuery);