A calendar-like date control without refreshing the page.

Source: Internet
Author: User
Tags datetime goto
1. A calendar-like date control without refreshing the page.
2. Determine if the value in the text control can be converted to a date type.

. HTC Example 1:
/*
*xpmask.htc
*
*/

//------------------------------------------------------------------------------------------------------

<public:component
Lightweight=false
>

<public:defaults
Contenteditable=false
Tabstop=true
/>

<public:attach event= "Ondocumentready" onevent= "Initcoolmask ()"/>
<public:attach event= "Ondetach" onevent= "Cleanupcoolmask ()"/>

<public:property name= "Masktype" value= ""/>
<public:property name= "Realvalue" value= ""/>
<public:property name= "Tooltipstr" value= ""/>

<script language= "VBScript" >


Sub Initcoolmask ()
Attachevent "onReadyStateChange", GetRef ("Coolmaskinputblur")
Attachevent "onfocus", GetRef ("Coolmaskinputfocus")
Attachevent "Onblur", GetRef ("Coolmaskinputblur")
Coolmaskinputblur
End Sub

Sub Cleanupcoolmask ()
DetachEvent "onReadyStateChange", GetRef ("Coolmaskinputblur")
DetachEvent "onfocus", GetRef ("Coolmaskinputfocus")
DetachEvent "Onblur", GetRef ("Coolmaskinputblur")
End Sub

Sub Coolmaskinputfocus ()
with element
If not. Realvalue = "" then. Value =. Realvalue
. Select ()
End With
End Sub

Sub Coolmaskinputblur ()
with element
Select Case UCase (. Masktype)
Case "DATETIME"
. Realvalue =. Value
. Value = Maskdatetime (. Value)
. Tooltipstr =. ToolTip
Case "ShortDate"
. Realvalue =. Value
If Maskdate (. Value, "short") = FormatDateTime ("1900-1-1 0:00:00", vbshortdate) Then
. Value = ""
. tooltipstr = "Format:yyyy-mm-dd"
Else
. Value = Maskdate (. Value, short)
If not. Realvalue = "" Then
. Tooltipstr = "Format:" &.realvalue
Else
. tooltipstr = "Format:yyyy-mm-dd"
End If
End If
. Title =.tooltipstr
Case "Mediumdate"
. Realvalue =. Value
. Value = Maskdate (. Value, "Medium")
Case "Longdate"
. Realvalue =. Value
. Value = Maskdate (. Value, "long")
Case "ZIPCODE"
. Realvalue = Parsechar (. Value, Array ("", "-"))
. Value = Maskzip (. Value)
Case "PHONE"
. Realvalue = Parsechar (. Value, Array ("," (","), "-", "."))
. Value = Maskphone (. Value)
Case "PERCENT"
. Realvalue = Parsechar (. Value, Array ("",%))
. Value = Maskpercent (. Value)
Case Else
. Realvalue =. Value
End Select
End With
End Sub

function Parsechar (SSTR, Schar)
Dim i, Zchar, snewstr
If TypeName (Schar) = "string" Then Zchar = Array (schar) Else Zchar = Schar
Snewstr = SStr
For i = LBound (Zchar) to UBound (Zchar)
SNEWSTR = replace (Snewstr, CStr (Zchar (i)), "")
Next
Parsechar = Snewstr
End Function

function Setviewstate (bstate)
with element
If not bstate then
. Runtimestyle.color =. Style.color
Else
. Runtimestyle.color = "Red"
End If
End With
End Function

function Maskdate (svalue, Stype)
If IsNumeric (svalue) Then
' svalue = Parsechar (svalue, Array ("", "-", "/", ",", ".", "\", "^", "&", "*", "@", "~", "", "" "," "," "," "!", "#", "$", "%", "|", "(", ")", "+", "_", "=", ";", "?", ":", "{", "}", "[", "]", "<", ">")
If Len (svalue) = 8 Then svalue = Left (svalue, 4) & "-" & Left (Right (svalue, 4), 2) & "-" & Right (SVa Lue, 4), 2
If Len (svalue) = 6 Then svalue = Left (svalue, 4) & "-0" & Left (Right (svalue, 2), 1) & "-0" & Right (s Value, 2), 1
End If
Dim zmonth
Zmonth = Array ("January", "February", "March", "April", "may", "June", "July", "August", "September", "October", "November "," December ")
If Len (Trim (svalue)) = 0 Then
Maskdate = ""
Setviewstate false
ElseIf Not (IsDate (svalue)) Then
Maskdate = "DATE ERROR"
Setviewstate true
Else
Select Case (Stype)
Case "Medium"
Maskdate = Day (DateValue (svalue)) & "-" & Left (Zmonth (month (dateValue)-1), 3) & "-" & Year (svalue Alue (svalue))
Case "Long"
Maskdate = Zmonth (Month (DateValue (svalue))-1) & "" & Day (DateValue (svalue)) & "," & Year (DateValue Lue))
Case Else
Maskdate = FormatDateTime (svalue, Vbshortdate)
End Select
Setviewstate false
End If
End Function

function Maskdatetime (svalue)
Dim snewvalue
Snewvalue = Parsechar (svalue, Array ("", "-", "/", ",", ".", "\", "^", "&", "*", "@", "~", "", "" "," "," "," "!", "#", "$", "% "," | "," (",") "," + "," _ "," = ","; ","? ",": "," {","} "," [","] "," < "," > ")
If Len (snewvalue) = 0 Then
Maskdatetime = ""
Setviewstate false
ElseIf (Len (snewvalue) <> 8 and Len (Snewvalue) <> 7 and Len (Snewvalue) <> 6) or not IsNumeric (Snewvalue) Then
Maskdatetime = "DATE ERROR"
Setviewstate true
Else
If Len (snewvalue) = 8 Then Snewvalue = Left (Snewvalue, 4) & "-" & Left (Right (Snewvalue, 4), 2) & "-" & Rig HT (Right (Snewvalue, 4), 2)
If Len (snewvalue) = 7 Then
If IsNumeric (Right (svalue, 2)) then
Snewvalue = Left (Snewvalue, 4) & "-0" & Left (Right (Snewvalue, 3), 1) & "-" & Right (right (Snewvalue, 3), 2)
Else
Snewvalue = Left (Snewvalue, 4) & "-" & Left (Right (Snewvalue, 3), 2) & "-0" & Right (right (Snewvalue, 3), 1)
End If
End If
If Len (snewvalue) = 6 Then Snewvalue = Left (Snewvalue, 4) & "-0" & Left (Right (Snewvalue, 2), 1) & "-0" & R Ight (Right (Snewvalue, 2), 1)
If not (IsDate (snewvalue)) Then
Maskdatetime = "DATE ERROR"
Setviewstate true
Else
' Snewvalue = Parsechar (snewvalue, Array ("", "-", "/", ",", "."))
Maskdatetime = FormatDateTime (Snewvalue, 2)
Setviewstate false
End If
End If
End Function

function Maskzip (svalue)
Dim snewvalue
Snewvalue = Parsechar (svalue, Array ("", "-"))
If Len (snewvalue) = 0 Then
Maskzip = ""
Setviewstate false
ElseIf (Len (snewvalue) <> 5 and Len (snewvalue) <> 9) or not IsNumeric (Snewvalue) Then
Maskzip = "ZIPCODE ERROR"
Setviewstate true
Else
If Len (snewvalue) = 9 Then Snewvalue = Left (Snewvalue, 5) & "-" & Right (Snewvalue, 4)
Maskzip = Snewvalue
Setviewstate false
End If
End Function

function Maskphone (svalue)
Dim snewvalue
Snewvalue = Parsechar (svalue, Array ("", "(", ")", "-", "."))
If Len (snewvalue) = 0 Then
Maskphone = ""
Setviewstate false
ElseIf (Len (snewvalue) <> 7 and Len (Snewvalue) <>) or not IsNumeric (Snewvalue) Then
Maskphone = "PHONE ERROR"
Setviewstate true
Else
Select Case Len (snewvalue)
Case 7
Maskphone = Left (Snewvalue, 3) & "-" & Right (Snewvalue, 4)
Case 10
Maskphone = "(& Left (Snewvalue, 3) &") "& Mid (Snewvalue, 4, 3) &"-"& Right (Snewvalue, 4)
End Select
Setviewstate false
End If
End Function

function Maskpercent (svalue)
Dim snewvalue
Snewvalue = Parsechar (svalue, Array ("", "%"))
If Len (snewvalue) = 0 Then
Maskpercent = ""
Setviewstate false
Else
On Error Resume Next
Err.Clear
Maskpercent = FormatPercent (snewvalue)
If Err.Number = Then
On Error Goto 0
Maskpercent = "PERCENT ERROR"
Setviewstate true
Exit function
End If
On Error Goto 0
Setviewstate false
End If
End Function

</script>

</PUBLIC:COMPONENT>


//------------------------------------------------------------------------------------------------------

. css Example 1:
/*
*xptext.css
*
*/

. coolmask
{
font-size:10pt;
Behavior:url (.. /HTC/COOLMASK.HTC);
Font-family:verdana, Arial, Helvetica;
}

//------------------------------------------------------------------------------------------------------

Page calls:

<asp:textbox id= "Birthday" cssclass= "Coolmask" ondblclick= "Javascript:setday" (this); "Masktype=" ShortDate "runat=" "Server" width= "106px" ></asp:textbox>

Attention:
Cssclass= "Coolmask" This is needless to say, and we all know what it is.
ondblclick= "Javascript:setday" (this); "It's a double shock event.
The masktype= "shortdate" Masktype attribute is defined in Coolwindowscalendar.js Chinese,
There are several Masktype property types:
DateTime: Date
ShortDate: Date
Mediumdate: Date
Longdate: Date
Phone: Telephone number
PERCENT: Percentage

Realvalue= "": Realvalue attribute is defined in Coolwindowscalendar.js Chinese,
Realvalue: Used to save the current value (Element.realvalue = textbox.value)

The TOOLTIPSTR:TOOLTIPSTR attribute is defined in Coolwindowscalendar.js Chinese,
TOOLTIPSTR: Used to display the format, is the title prompt box,

View Address: http://print.itgaga.org/PrintERP/OrderManage/Bus_Invoice_EFrame.aspx (date of completion)

Source code: Data.rar




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.