I'm attempting to write what may be my first jQuery/javascript code (rather than copy/paste/tweaking) and have run into an issue I'm not quite how to resolve.
I have a title input field (in this case in a Drupal site) that I want to auto-populate the content into based on the choices made on three other input elements... a radio input element, then two select elements. It's all working at this point, but the input values for the month options are numerical verse text, and I need to feed the name of the month to the title.
So, I have a form of this working now where it simply takes the value of each input and appends it to the title input field whenever the year input select is modified.
I've attempted to create a switch case to define a variable (theMonth) which is used instead of the numerical input value when the concatenated string is populated into the title input.
But the code below is throwing an error on the site. I'm guessing it's something really simple, but as a jQuery/javascript newb I thought I could use some schooling... Help appreciated.
- jQuery(document).ready(function($) {
- $("input[name='field_archive_publication']:checked, #edit-field-select-month, #edit-field-archive-select-year").change(function(){
- var inMonth = $("input[name='field_archive_publication']:checked").val();
- var theMonth;
- switch(inMonth){
- case 01:
- var theMonth = 'January';
- break;
- case 02:
- var theMonth = 'February';
- break;
- case 03:
- var theMonth = 'March';
- break;
- case 04:
- var theMonth = 'April';
- break;
- case 05:
- var theMonth = 'May';
- break;
- case 06:
- var theMonth = 'June';
- break;
- case 07:
- var theMonth = 'July';
- break;
- case 08:
- var theMonth = 'August';
- break;
- case 09:
- var theMonth = 'September';
- break;
- case 10:
- var theMonth = 'October';
- break;
- case 11:
- var theMonth = 'November';
- break;
- case 12:
- var theMonth = 'December';
- break;
- }
- concatenated_string = $(theMonth).val() + " " + $("#edit-field-select-month").val() + " " + $("#edit-field-archive-select-year").val();
- $(document).on('change', '#edit-field-archive-select-year', function() {
- $("#edit-title-0-value").val(concatenated_string);
- }).val( $('#edit-title-0-value').val() ).change();
- });
- });