Results 1 to 1 of 1

Thread: Jquery and dropdowns

  1. #1
    Thread Starter
    Amateur cypco's Avatar
    Join Date
    Apr 2012
    Location
    Colombia
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Jquery and dropdowns

    Hello,

    I have 2 dropdowns (main_cat and sub_cat)... the second one is disabled and should be enabled when the first one is changed.
    When the first dropdown is changed, it enters (to prove this, I added this line alert('The option with value main_cat ' + $mainCat); and the alert shows correctly).
    However, the problem comes with this line: jQuery("#sub_cat").prop("disabled", true); because it does nothing.

    I checked the code in jsFiddle (jQuery 1.8.3) and it works perfectly, but when placing it in Classipress, it doesn't work.
    I also tried with jQuery("#sub_cat").attr("disabled","disabled");

    All the following code is in a child theme, in a new file that is called from wrapper.php.

    Any ideas why it is not working or how can I make it work?

    Here is the whole code:

    HTML
    HTML Code:
    <?php 						wp_dropdown_categories('show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=1&show_option_none=Type&taxonomy='.APP_TAX_CAT.'&name=main_cat&id=main_cat');										
    ?>
    					
    <select name="sub_cat" id="sub_cat" disabled="disabled">
    	<option selected="selected" disabled="disabled" value="none">Brand</option>
    	<option>Option 1</option>   
    	<option>Option 2</option>
    </select>
    JQUERY

    Code:
    jQuery(function ($) 
    {
      
      jQuery("#main_cat").change(function() 
      {	
    	var $mainCat=$('#main_cat').val();
    	alert('The option with value main_cat ' + $mainCat); //this is to check that it is entering when main_cat is changed
        $("#sub_cat").empty();    
        jQuery("#sub_cat").prop("disabled", true);	
         
      });
      
    });

    Thanks in advance.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Jomark Pre-define search fields with dropdowns
    By jubalince in forum JobRoller General Discussion
    Replies: 4
    Last Post: June 2nd, 2013, 07:38 PM
  2. Dimitris Old jQuery version if 'Google CDN jQuery' is activated?
    By per4mance in forum Report JobRoller Bugs
    Replies: 2
    Last Post: March 10th, 2013, 04:27 PM
  3. [MOD NEEDED] Category dropdowns
    By estrates in forum ClassiPress General Discussion
    Replies: 1
    Last Post: July 30th, 2012, 04:31 AM
  4. Special search dropdowns
    By kajaja in forum ClassiPress General Discussion
    Replies: 1
    Last Post: May 26th, 2011, 09:33 AM