Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
hey,

with all forum help i archived to populate datepicker in Textbox

Textbox1
C#
$('#txtSeparationDate').datepicker({ dateformat: 'dd-mm-yyyy', showOn: "button",
        buttonImage: '/Images/calendar1.gif',
        buttonText:"Choose a date",
        buttonImageOnly: true, hideIfNoPrevNext: true
    });


Textbox2
C#
$('#txtbirthdate').datepicker({ dateformat: 'dd-mm-yyyy', showOn: "button",
       buttonImage: '/Images/calendar1.gif',
       buttonText: "Choose a date",
       buttonImageOnly: true, hideIfNoPrevNext: true
   });


but really i don't want to write this twice how can i apply this Jquery datepicker for both Textbox

Thanks
Help highly needed
Posted

Hi there,

This is very easy since jQuery uses CSS selectors to get elements. Instead of writing it twice, put both selectors into the one statement and it will apply the datepicker to both. E.g.

JavaScript
$("#txtbirthdate, #txtSeparationDate").datepicker({ 
       dateformat: "dd-mm-yyyy", 
       showOn: "button",
       buttonImage: "/Images/calendar1.gif",
       buttonText: "Choose a date",
       buttonImageOnly: true, 
       hideIfNoPrevNext: true
   });


Hope this helps,
Ed
 
Share this answer
 
Comments
kimberly wind 31-May-12 4:47am    
my 5! helped alot
Another way is to simply add a CSS class to all your text boxes, then you can attach by class name, e.g

Your MVC markup...(just make sure you add the class attribute)
HTML
<![CDATA[<%= Html.TextBoxFor("LastName", Model.LastName, new { @class = "date-picker" })%>]]>


Jquery init...

JavaScript
$('.date-picker').datepicker({ dateformat: 'dd-mm-yyyy', showOn: "button",
       buttonImage: '/Images/calendar1.gif',
       buttonText: "Choose a date",
       buttonImageOnly: true, hideIfNoPrevNext: true
   });
 
Share this answer
 
Comments
kimberly wind 31-May-12 4:47am    
Great help my 5! :P :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900