Wednesday 15 January 2014

JQuery and Dropdowns in Wordpress -


I have 2 dropdowns (main and subset) in WordPress ... The second one is disabled and when should be enabled for the first time One has changed when the first dropdown changes, it enters (To prove this, I've added this line alert (option with 'value main_cat' + $ mainCat); and shows the warning properly). 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 it is placed in the classpress, it does not work. Attri ("disabled", "disabled");

All the following codes are in a child subject.

Any idea why this is not working or how can I work it out?

HTML

  & lt; Select name = "main_cat" id = "main_cat" & gt; & Lt; Option selected = "selected" disabled = "disabled" value = "none" & gt; Type & lt; / Options & gt; & Lt; Options & gt; Option 1 & lt; / Options & gt; & Lt; Options & gt; Option 2 & lt; / Options & gt; & Lt; / Select & gt; & Lt; Select name = "sub_cat" id = "sub_cat" disabled = "disabled" & gt; & Lt; Option selected = "selected" disabled = "disabled" value = "none" & gt; Brand & lt; / Options & gt; & Lt; Options & gt; Option 1 & lt; / Options & gt; & Lt; Options & gt; Option 2 & lt; / Options & gt; & Lt; / Select & gt; (Function ($) {jQuery ("# ​​main_cat"). Change (function () {var $ mainCat = $ ('#main_cat'). Val (); // Check that when main_cat is alerted (Option with 'value main_cat' + $ mainCat); $ ("# sub_cat"); empty (); jQuery ("#sub_cat") .prop ("disabled", true);});});  

Your closing "jquery" has no reference, using $ in that funciton

Edit : You'll need to add the "disabled" attribute, such as before adding it.

  jQuery ("# ​​main_cat") .on ("change", function () {var $ mainCat = $ ('# main_cat'). Val (); Warning ('value Option with main_cat '+ $ mainCat); // is to check that when main_cat $ ("# sub_cat") is changing, removeAttr ("disabled");});    

No comments:

Post a Comment