How can I show/hide option in drop down list?
Hi
I am trying to show and hide option in a drop down menu using jQuery.
I pass an id to a php file using getSON then i return ids list. Then I do a check for every option in a menu if this option value exists in the array show it otherwise hide it.
this is my current error
Uncaught Error: Syntax error, unrecognized expression: #result_code_menu option[value=[object Object]]
This is my current code
- $(document).ready(function() {
- $('#call_code_menu').change( function(){
- $.getJSON("ajax/getResutCode.php", {
- id: $(this).val()
- },function (data) {
-
- if ( ! data)
- return;
-
- var rsToUse = new Array();
-
- $.each(data ,function(i,v){
- rsToUse.push(v);
- console.log( v );
- });
-
- $("#result_code_menu option").each(function() {
- if( $.inArray( $(this), rsToUse) )
- $("#result_code_menu option[value=" + $(this) + "]").show();
- else
- $("#result_code_menu option[value=" + $(this) + "]").hide();
- });
-
-
- });
-
-
- });
-
- });
Can some one help me with this please
thanks