How to trigger background code after the value of the HTML text box changes

Source: Internet
Author: User

Copy codeThe Code is as follows: <asp: TextBox ID = "txtDate" CssClass = "Wdate" Style = "width: 91px;" runat = "server"

Onfocus = "WdatePicker ({maxDate: '% y-% M-% d', isShowClear: false, readOnly: true })"
Onpropertychange = "showValue (this. value)"> </asp: TextBox>

Day
<Asp: HiddenField ID = "hiddenDate" runat = "server"

OnValueChanged = "hiddenDate_ValueChanged"
EnableViewState = "false"/>
<Div style = "display: none;">
<Asp: ImageButton ID = "btnHid" runat = "server"

ImageUrl = "~ /Resource/images/Btn_Find.gif"
CausesValidation = "false" align = "absmiddle"

OnClick = "btnHid_Click"/>
</Div>

To achieve this goal, you must use background code and javascript code. Javascript code

As follows:

Copy codeThe Code is as follows: <script type = "text/javascript">
// Record the date that the user entered last time.
Var today = new Date ();
Var todayMonth;
Var todayDate;

// Format the current "month" and "day.
If (today. getMonth () + 1) <10 ){
TodayMonth = "0" + (today. getMonth () + 1 );
}
If (today. getDate () <10 ){
TodayDate = "0" + today. getDate ();
}

// Obtain the current date.
Var oldValue = http://www.jb51.net/Health/archive/2012/02/10/today.getFullYear () + "-" + todayMonth + "-" + todayDate;

Function showValue (obj ){
// When the query date is not blank, the query button is triggered.
If (obj! = "" & Obj! = OldValue ){
OldValue = http://www.jb51.net/Health/archive/2012/02/10/obj;
$ ('# TxtName'). get (0). select ();
$ ("# HiddenDate"). val (obj );
$ ('# BtnHid'). trigger ("click ");
Return false;
}
}
</Script>

Javascript code mainly determines whether the selected date is not blank and is a new date. Will trigger

The OnValueChanged of the hidden control can also trigger a button event. Date control event

It is the javascript code used for onpropertychange = "showValue (this. value.
The following is the background code:

Copy codeThe Code is as follows: // query based on the selected time.
Protected void hiddenDate_ValueChanged (object sender, EventArgs e)
{
// Background code
}

// Query based on the selected time.
Protected void btnHid_Click (object sender, ImageClickEventArgs e)
{
// Background code
}

Both can be used.
This blog post only shows how to use the front-end non-Server Control text box (although this blog post uses Server Control

Is the same as HTML controls .), Text changes trigger background events to execute background code.

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.