I am using a dropdown plugin called dropkick, which replaces select menus with better looking, custom dropdowns. I want to display my list of WordPress categories in this dropdown. Here is the PHP code that generates the dropdown:
<form action="<?php bloginfo('url'); ?>/" method="get" class="pretty">
<?php $select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
echo $select; ?>
</form>
The JavaScript code to turn this into a “pretty dropdown” is as follows.
$('.pretty select').dropkick({
theme: 'default',
change: function (value, label) {
INSERT CALLBACK HERE
}
});
I need to write a callback that will submit the form after the user selects a category. How would I go about this?
I tried using return this.form.submit()
and also return $(this).parent().form.submit()
but that did not submit the form. How can I auto submit a form using jQuery?
The form action and method are already defined in the form.
Christofer Eliasson’s answer may be correct, but just in case you have more than one form, this would be better:
You can use jQuery’s
.submit()
to post the form.Given that you only have one form in the DOM with the class
pretty
, you could post the form like this: