holly_mbd
asked on
Help using jquery change event for drop down list
Hello,
I am trying to use a drop down box on my page. When a user selects a category from the list, I want to perform a function (filtering a table). I know the code for my table and the function to filter it is correct - it's selecting an option and running the function that I can't get to work.
I'm currently using this exact same script on another page, only instead of using the .change event, I am using .click because the categories are displayed as links. In this case, there are so many categories that I want them to be displayed as a drop down box instead, so I was pretty sure that I just needed to change the script to use the .change event, correct? I'm sure its something very simple, but I'm still new to javascript and jquery. Thanks for your help!
I am trying to use a drop down box on my page. When a user selects a category from the list, I want to perform a function (filtering a table). I know the code for my table and the function to filter it is correct - it's selecting an option and running the function that I can't get to work.
I'm currently using this exact same script on another page, only instead of using the .change event, I am using .click because the categories are displayed as links. In this case, there are so many categories that I want them to be displayed as a drop down box instead, so I was pretty sure that I just needed to change the script to use the .change event, correct? I'm sure its something very simple, but I'm still new to javascript and jquery. Thanks for your help!
drop down box html:
<select id="categories">
<option>Select a Category</option>
<option id="showAccomodations">Accommodations/Lodging/Travel</option>
<option id="showAccounting">Accounting/Bookkeeping/Tax Services</option>
<option id="showAdvertising">Advertising/Promotions</option>
<option id="showAgricultural">Agricultural Equipment/Sales/Repair</option>
<option id="showAuto_Truck_Sales">Auto/Truck Sales</option>
</select>
script:
<script type="text/javascript" src="http://www.mercerbusinessdirectory.com/jquery.dataTables.js">
</script>
<script type="text/javascript" charset="utf-8">
var filterCategory;
$(document).ready(function() {
filterCategory = $('#listings').dataTable( {
"iDefaultSortIndex": 0,
"sDefaultSortDirection": "asc",
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"aoData": [{ "sType": "html" },null,null]
} );
$('#listings').hide();
$('#listings_filter').hide();
$('#showAccomodations').change(function () {
filterCategory.fnFilter( 'Accomodations/Lodging/Travel' );
$('#listings').show();
} );
$('#showAccounting').change(function () {
filterCategory.fnFilter( 'Accounting/Bookkeeping/Tax Services' );
$('#listings').show();
} );
$('#showAdvertising').change(function () {
filterCategory.fnFilter( 'Advertising/Promotions' );
$('#listings').show();
} );
$('#showAgricultural').change(function () {
filterCategory.fnFilter( 'Agricultural Equipment/Sales/Repair' );
$('#listings').show();
} );
$('#showAuto_Truck_Sales').change(function () {
filterCategory.fnFilter( 'Auto/Truck Sales' );
$('#listings').show();
} );
} );
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER