How do I use javascript events with the custom fields. - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com2013-06-20T03:32:12Zhttp://fogbugz.stackexchange.com/feeds/question/10655http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://fogbugz.stackexchange.com/questions/10655/how-do-i-use-javascript-events-with-the-custom-fieldsHow do I use javascript events with the custom fields. aStokes2012-07-31T18:28:49Z2012-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><select valueDefault="--" name="P7_subcategoryp32" title="My Title" tabindex="401" id="subcategoryp32" >
<option value="--">--</option><option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</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#10662Answer by aStokes for How do I use javascript events with the custom fields. aStokes2012-08-01T14:17:32Z2012-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>