I’m not sure if this is a SilverStripe or a JavaScript issue because I am new to JS but here goes.
I am trying something that should be simple but having trouble. I want to show/hide a field based on a dropdown. It is 50% working as the field is hidden/shown when toggled but only if rejected is selected when the document loads. Can anyone spot my mistake so I don’t spend weeks on this? I’ve used firebug and found that the field never gets added if it’s pending or accepted.
jQuery = jQuery.noConflict();
(function($) {
$(document).ready(function(){
var dropDown = $('#DataObjectManager_Popup_DetailForm_Status');
var reason = $('#Reason');
if(dropDown.val() == 'rejected' || dropDown.val() == 'Rejected'){
reason.show();
}
dropDown.change(function (e) {
if(dropDown.val() == 'rejected'){
reason.show();
}
else{
reason.hide();
}
}).change();
});
})(jQuery);
Thanks
This is unrelated to your Silverstripe code. I’ve put together a fiddle for you:
http://jsfiddle.net/tq2Qy/1/
Let me know if you’ve any questions