Javascript code:
// Check whether the customer name exists
Method 1:
Function SearchCustName ()
{
Var name = escape (document. getElementById ("txt_Custname"). value );
Var a = Test. GetCustName (name). value;
Document. getElementById ("txtname"). innerText = a; // when using DIV, it is available in IE6.0 but not in IE7.0.
}
Method 2:
Function SearchCustName ()
{
Var name = escape (document. getElementById ("txt_Custname"). value );
Var a = Test. GetCustName (name). value;
Document. getElementById ("txtname"). value = a; // It is available in IE7.0 and IE6.0 when DIV is used.
}
Add_Customer.aspx code
When method 1 is used:
Customer name: <input id = "txt_Custname" runat = "server" onchange = "SearchCustName ()" type = "text"/>
<Span style = "color: # ff0000"> * </span> <div id = "txtname"> </div> <span style = "color: # ff0000 "> </span> </td>
When method 2 is used:
Customer name: <input id = "txt_Custname" runat = "server" onchange = "SearchCustName ()" type = "text"/>
<Span style = "color: # ff0000"> * </span>: <input id = "txtname" type = "text"/>
Test. cs code:
[Ajax. AjaxMethod ()]
Public string GetCustName (string Custname)
{
String SQL = "select * from MERs where cust_name = '" + custname + "'";
Sqldatareader DR = Co. getdatareader (SQL );
If (dr. Read ())
{
Return "prompt: this user already exists. Please enter it again! ";
}
Else
{
Return "";
}
}
As this talent started to learn Ajax and has limited familiarity with JavaScript, please kindly advise me. Thank you!