Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter date value in Text Box

Status
Not open for further replies.

BTon15

Programmer
Nov 21, 2001
29
GB
I have a Text Box on my ASP.Net page with a mask of 99/99/9999, and it should only accept a Date. I want to be able to type in only a 0 as a shortcut and have some Javascript change the value to the current date. I'm using the OnBlur event on my page to call the Javascript function:

<asp:TextBox runat="server" onblur="SetToCurrentDate(this);" />

My Javascript function looks something like this:

function SetToCurrentDate(myDate)
{
if (myDate.value == "0_/__/____")
{
myDate.value = "15/04/2010";
}
}

I know that I'm getting into the if condition as I've tried using an alert to display a message. However, my Text Box is not getting its value changed to 15/04/2010.

I'm sure I've got something pretty straightforward wrong here, but as a newcomer to ASP.Net and Javascript, I'm really scratching my head with this.

I'd really appreciate any advice.

Thanks.
 

1. Show us the final rendered HTML code, not the ASP stuff. So we can see what your rendered textbox looks like.

2. How are you setting the mask? If by JS, the mask function itself may be interfering with the new value. That is it gets the value but the mask function resets it.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top