How do I use javascript events with the custom fields. - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com 2013-06-20T03:32:12Z http://fogbugz.stackexchange.com/feeds/question/10655 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://fogbugz.stackexchange.com/questions/10655/how-do-i-use-javascript-events-with-the-custom-fields How do I use javascript events with the custom fields. aStokes 2012-07-31T18:28:49Z 2012-08-01T14:17:32Z <p>So I have a small problem. I want to enable/disable the ok button if the user selects/deselects the default field on a drop down box. I found the correct id name but there is no onchange event in the html. </p> <pre><code>&lt;select valueDefault="--" name="P7_subcategoryp32" title="My Title" tabindex="401" id="subcategoryp32" &gt; &lt;option value="--"&gt;--&lt;/option&gt;&lt;option value="One"&gt;One&lt;/option&gt; &lt;option value="Two"&gt;Two&lt;/option&gt; &lt;option value="Three"&gt;Three&lt;/option&gt; </code></pre> <p>This is what I'm trying to do. I go the idea from the bugmonkey script archive.</p> <pre><code>$(document).ready(function(){ // don't do anything if we're not on the case edit page if (!$('#bugviewContainer').length) return; // $(this).attr("title", "Facilita Support"); var okButton = $('#Button_OKEdit')[0]; if (!okButton) return; okButton.disabled = true; okButton.title = "Subcategory cannot be blank"; var verifyFields = function(event) { var okButton = $('#Button_OKEdit')[0]; if (($('#subcategoryp32').selectedIndex == 0)) { okButton.disabled = false; okButton.title = ""; } else { okButton.disabled = true; okButton.title = "Subcategory cannot be blank"; } if (this.originalOnChange) this.originalOnChange(event); } var dropDown = $('#subcategoryp32'); if (dropDown.onkeyup) dropDown.originalOnChange= titleText.onchange; dropDown.onchange = verifyFields; }); </code></pre> http://fogbugz.stackexchange.com/questions/10655/how-do-i-use-javascript-events-with-the-custom-fields/10662#10662 Answer by aStokes for How do I use javascript events with the custom fields. aStokes 2012-08-01T14:17:32Z 2012-08-01T14:17:32Z <p>Thanks db. Using jquery did the trick. Here is the updated script</p> <pre><code>$(document).ready(function(){ // don't do anything if we're not on the case edit page if (!$('#bugviewContainer').length) return; var okButton = $('#Button_OKEdit')[0]; if (!okButton) return; if (($('#subcategoryp32')[0].value == "--")) { okButton.disabled = true; okButton.title = "Subcategory cannot be blank"; } var dropDown = $('#subcategoryp32'); dropDown.on("change", function(event){ if (($('#subcategoryp32')[0].value != "--")) { okButton.disabled = false; okButton.title = ""; } else { okButton.disabled = true; okButton.title = "Subcategory cannot be blank"; } dropDown.originalOnChange = dropDown.on("change", function(){}); dropDown.on("change", function(){}) = verifyFields; }) }); </code></pre> <p>So the OK button will remain disabled until they change the drop value. </p>