c# - asp.net update textbox via JS based on other textbox value -


i have 2 textboxes on asp.net page. 1 today's date , 1 expiry date 1 year now.

so if first textbox contains 23/04/2013

i want second textbox automatically populated 23/04/2014

how can update expiry date's date 1 year (without postback) suspect js needed right?

this answer uses jquery read date, parse parts , add 1 year. doesn't, check validity of date entered, entering letters first textbox produce date of "nan/nan/nan". combine jquery ui's datepicker make sure input valid date. in case use change event instead of keyup.

html:

<input id="today" type="text" /> <input id="future" type="text" /> 

javascript:

$(document).ready(function () {     $('#today').keyup(function () {         var today = new date($(this).val());         if (today != nan) {             var dd = today.getdate();             var mm = today.getmonth();             var y = today.getfullyear();             $('#future').val(dd + '/' + mm + '/' + (parseint(y)+1));         }     }); }); 

working example: http://jsfiddle.net/6vs5y/


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -