how to get textbox click event in asp.net

Posted by Bhavna81 under Regular Expressions on 11/25/2009 | Views : 8533 | Status : [Member] | Replies : 2
hello experts,

in my asp.net application i need current date value in textbox, when i click that textbox.

how can i do...

please help..
thanks.




Responses

Posted by: Abhijit Jana on: 11/25/2009 [Member] [MVP] Bronze

Up
0
Down
<input type="button" id="btnDate" value="" onclick="SetDate();" />



on SetDatefunction you can set the TextBox value as follows :
function SetDate()

{
var cd = new Date()
var month = cd .getMonth() + 1
var day = cd .getDate()
var year = cd .getFullYear()
var txtID= document.getElementByID(btnDate);
txtID.value=month + "/" + day + "/" + year'

}



Cheers !
Abhijit

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Virendradugar on: 11/25/2009 [Member] [MVP] Silver

Up
0
Down
Hi Bhavana,

You can also use Javascript event onFocus() to set the current date value in text box.

Check below link for more details about onFocus() function.

http://www.java-scripts.net/javascripts/Clear-Form-onFocus().phtml

Bhavna81, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response