When creating a new article, how can I get the current selected category ID as shown in the category select field? I need to pass the value to a PHP variable.
There is the javascript function categoryHasChanged(element)
in the page at administrator/index.php?option=com_content&view=article&layout=edit
which is getting the category ID from a PHP function, I just haven't determined how.
function categoryHasChanged(element) {
var cat = jQuery(element);
if (cat.val() == '2')return;
Joomla.loadingLayer('show');
jQuery('input[name=task]').val('article.reload');
Joomla.submitform('article.reload', element.form);
}
jQuery( document ).ready(function() {
Joomla.loadingLayer('load');
var formControl = '#jform_catid';
if (!jQuery(formControl).val() != '2'){jQuery(formControl).val('2');}
});
The function is used in the category select field in the onchange=""
attribute
<select id="jform_catid" name="jform[catid]" data-custom_group_text="New Categories" data-no_results_text="Add new Category" data-placeholder="Type or Select a Category" data-custom_value_prefix="#new#" class="required chzn-custom-value" required aria-required="true" onchange="categoryHasChanged(this);">
<option value="2">Uncategorised</option>
<option value="8">The Green Mile</option>
</select>
How is the category ID delivered for a new article?