0

Im having issues with a jquery script (below) which should change the format of the date within a date picker, input field (named 'jform[moving_date]').

var months = ['Jan','Feb','May','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var element = $('input[name=jform[moving_date]]');
element.on('change', function(e) {

// You might need to stop propagation but this will cause other scripts from firing like date picker.
// e.stopPropagation();

var date_parts = $(this).val().split('-');
var month_index = Number(date_parts[1]) - 1;
var date_new = date_parts[0] + '-' + months[month_index] + '-' + date_parts[2];
$(this).val(date_new);
}); 

The current date format is: 31-12-2016

I need it in the following format: 31-Dec-2016

Many thanks in advance!

  • What issues do you have? @jimmywiddle – Aleksandar Đokić Jul 24 '16 at 10:30
  • Your code work fine. What is your propblem? – Mohammad Jul 24 '16 at 11:05
  • @Alexandar Error: Syntax error, unrecognized expression: input[name=jform[moving_date]] ...value:null},db.error=function(a){throw new Error("Syntax error, unrecognized exp... – jimmywiddle Jul 24 '16 at 13:28
  • @Mohammad error is above ..sorry I should have included this in my initial post. (I couldn't @ 2 users in 1 comment thats why theres 2) – jimmywiddle Jul 24 '16 at 13:30
  • Your problem is using `[]` in `name` attribute. You need to use `$('input[name=jform\\[moving_date\\]]')` selector. Check [this](http://stackoverflow.com/questions/2364982/jquery-selector-for-inputs-with-square-brackets-in-the-name-attribute) – Mohammad Jul 24 '16 at 13:35
  • @Mohammad Many thanks for the reply/help! But im afraid to say its still not working for me :( I even tried using the id `var element = $('#jform_moving_date');` but im having no luck at all here, any thoughts at all on what i might be doing wrong? Thank again! – jimmywiddle Jul 24 '16 at 14:35
  • Are you sure change event is fired? – Mohammad Jul 24 '16 at 14:37
  • Im using `$('.jsndatepicker-days').click(function(){` absolutely no luck here:( id so much appreciate it if any further ideas, many thanks! – jimmywiddle Jul 25 '16 at 03:30

0 Answers0