html - jQuery ui.datepicker on 'select' element -


i have select element couple of dates want give possibility of picking date datepicker have following code displays calendar icon next select field.

<select name="birthday" >      <option value="${merge0.birthday}">${merge0.birthday}</option>      <option value="${merge1.birthday}">${merge1.birthday}</option>                         </select> <input type="hidden" id="bday_icon" /> 

then, datepicker script

$("#bday_icon").datepicker(             {                 changemonth: true,                 changeyear: true,                 showon: 'button',                 buttonimage: 'cal/images/calendar.gif',                 buttonimageonly: true,                 onselect: function(datetext, inst) {                     var field = document.getelementsbynamebyname("birthday");                     var opt = document.createelement('option');                     opt.text = datetext;                     opt.value = datetext;                     field.add(opt, null);             }             }); 

shouldn't function onselect, add new option select html element? can't see it's wrong?

thanks.

update 1:

onselect: function(datetext, inst) {       var opt = $('<option />').attr('value', datetext).text(datetext);       $('select[name=birthday]').append(opt);       } 

works perfect, remark needed mark selected new option edit like: $('<option selected/>')

unless they're of functions, i'm not sure .add() , getelementsbynamebyname() are. can't seem find add in jquery api.

also, when working jquery widgets, prefer use jquery selectors:

onselect: function(datetext, inst) {     var opt = $('<option />').attr('value', datetext).text(datetext);     $('select[name=birthday]').append(opt); } 

works me.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -