Setting a field to a date in the future using jQuery or Javascript -


i need able set input field date 365 days current date. field sets expiration date of membership purchase. have javascript not work reason.

<input type="text" name="zoneexpiry" id="expirydate" /> <script type="text/javascript"> function setexpirydate( ) { var dat=new date(); dat.setdate(dat.getdate() + 45); var monthname=new array("jan","feb","mar","apr","may","jun",   "jul","aug","sep","oct","nov","dec") var pretty = dat.getdate() + "-" + monthname[dat.getmonth()] + "-" + dat.getfullyear();     document.getelementbyid("expirydate").value = pretty; } </script> 

i'm no javascript expert reason not setting input field proper value.

is there way fix javascript or accomplish similar task using jquery?

the date format needs 01-jan-2010, day-month-4digit year.

thanks help!

with jquery:

    <input type="text" name="zoneexpiry" id="expirydate" />     <script type="text/javascript">     $.fn.setexpirydate = function(expirationday) {        var dat = new date(),            pretty = 0,            monthname = new array("jan","feb","mar","apr","may","jun", "jul","aug","sep","oct","nov","dec");         dat.setdate(dat.getdate() + expirationday);         pretty = dat.getdate() + "-" + monthname[dat.getmonth()] + "-" + dat.getfullyear();         $(this).val(pretty);     }      $('#expirydate').setexpirydate(365);     ​</script> 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -