jquery

Add same class on select form item as selected option

This is a jQuery script for Drupal forms changing the select form class to the same as the selected option item. I use the change event on select item because Chrome doesn't allow click event on option tags.

<?php
  $script
= '$(document).ready(function() {
                 $("select.bj-status-selector").change(function(){
                       var optClass = $(this).children(":selected").attr("class");
                      $(".bj-status-selector").removeClass().addClass("form-select bj-status-selector " + optClass);
                 });
            });
            '
;
 
 
drupal_add_js($script, 'inline', 'footer');
?>

Add a monthly datepicker with jQuery - separate script

This script adds a month-year picker to a text field, and works better than a modification of jQuery datepicker.

<?php
drupal_add_js
(drupal_get_path('module', 'jquery_ui') .'/jquery.ui/ui/jquery.mtz.monthpicker.js');

$sub_script = "$(document).ready(function () {
         $('.add-datepicker-y-m').monthpicker({
            'pattern': 'mm/yyyy'
          })
        }); "
;

drupal_add_js($script, 'inline', 'footer');
?>

Source: https://github.com/lucianocosta/jquery.mtz.monthpicker

Add a datepicker programmatically with jquery_ui

This is some idea on how you can add a datepicker programmatically with the jquery_ui module. This code is not working as it is, its just some code I have cut out from my code. You have to match the form id in the jquery script as the drupal form creates. Look for edit-from, edit-to, edit-month in the script. I have here two alternative jquery scripts. And you find more scripts at the link to jqueryui.com below.