Submit Wordpress Form dropdown with Jquery onchange

不羁岁月 提交于 2019-12-12 00:54:44

问题


Similar to this question I would like to use dropdown plugin called dropkick, which replaces select menus with better looking, custom dropdowns. This time around, I want to put wordpress archives within a dropdown. The standard way of doing this is like so:

<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
  <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option> 
  <?php wp_get_archives( 'type=monthly&format=option&show_post_count=1' ); ?>
</select>

To adapt this technique for dropkick, I want to remove the onchange js part of the php so it looks like this:

<form action="???" method="get" class="prettyArchive">
    <select>
         <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option> 
         <?php wp_get_archives( 'type=monthly&format=option&show_post_count=1' ); ?>
    </select>
</form>

The jquery that converts this dropdown into a "pretty dropdown" is:

$('.prettyArchive select').dropkick({
      theme: 'default',
      change: function (value, label) {
         INSERT CALLBACK HERE
      }
});

I need a callback that will emulate the onchange event shown above. I do not believe the form needs to be submitted, but rather a page refresh on change? Not really sure how to go about this. Any ideas?


回答1:


Haven't used that particular plugin, so I'm not sure what values are being passed to the callback, but maybe something like this:

$('.prettyArchive select').dropkick({
      theme: 'default',
      change: function (value, label) {
         document.location.href=value;
      }
});


来源:https://stackoverflow.com/questions/10487431/submit-wordpress-form-dropdown-with-jquery-onchange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!