?
Solved

Textbox text change Event in Javascript

Posted on 2011-09-28
5
Medium Priority
?
295 Views
Last Modified: 2012-05-12
Hi,
  I want this below textbox_texchanged event in Javascript. Am not sure how to do this in Javascript. Please help.

 protected void txtPtID_TextChanged(object sender, EventArgs e)
        {
            if (txtPtID.Text != "")
            {
                txtFirstName.Text = "";
                txtLastName.Text = "";
                txtDOB.Text = "";
                txtStateID.Text = "";
                txtFirstName.Enabled = false;
                txtFirstName.BackColor = System.Drawing.Color.LightGray;
                txtLastName.Enabled = false;
                txtLastName.BackColor = System.Drawing.Color.LightGray;
                txtDOB.Enabled = false;
                txtDOB.BackColor = System.Drawing.Color.LightGray;
                txtStateID.Enabled = false;
                txtStateID.BackColor = System.Drawing.Color.LightGray;
            }
            else
            {
                txtFirstName.Enabled = true;
                txtFirstName.BackColor = System.Drawing.Color.Empty;
                txtLastName.Enabled = true;
                txtLastName.BackColor = System.Drawing.Color.Empty;
                txtDOB.Enabled = true;
                txtDOB.BackColor = System.Drawing.Color.Empty;
                txtPtID.Enabled = true;
                txtPtID.BackColor = System.Drawing.Color.Empty;
                txtStateID.Enabled = true;
                txtStateID.BackColor = System.Drawing.Color.Empty;
            }
        }
0
Comment
Question by:gladstonesheeba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36718653
you need write onblur event for text box.

<html><head><title>(Type a title for your page here)</title>

<script type="text/javascript">
function change_case()
{
document.form1.type.value=document.form1.type.value.toLowerCase();
}
</script>

</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onLoad="form1.type.focus();">

<form name=form1 method=post action=''''>
<input type=text name=type value=''Enter USER ID'' onblur="change_case();">
<input type=submit value=Submit> </form>

</body>
</html>

Refer links

http://stackoverflow.com/questions/384820/adding-javascript-to-the-onblur-property-of-an-asp-net-text-box-control

http://en.allexperts.com/q/Javascript-1520/Textbox.htm
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36718666
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1500 total points
ID: 36718697
Use :
<script language="javascript" type="text/javascript">
	window.onload = function() {
		document.getElementById("<%= txtPtID.ClientID %>").onchange = function() {
			if( this.value != "" ) {
				document.getElementById("<%= txtFirstName.ClientID %>").value = "";
				document.getElementById("<%= txtLastName.ClientID %>").value = "";
				document.getElementById("<%= txtDOB.ClientID %>").value = "";
				document.getElementById("<%= txtStateID.ClientID %>").value = "";
				
				document.getElementById("<%= txtFirstName.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtLastName.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtDOB.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtStateID.ClientID %>").removeAttribute("disabled");
				
				document.getElementById("<%= txtFirstName.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtLastName.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtDOB.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtStateID.ClientID %>").style.backgroundColor = "LightGray";
			}
			else {
				document.getElementById("<%= txtFirstName.ClientID %>").disabled = true;
				document.getElementById("<%= txtLastName.ClientID %>").disabled = true;
				document.getElementById("<%= txtDOB.ClientID %>").disabled = true;
				document.getElementById("<%= txtStateID.ClientID %>").disabled = true;
				
				document.getElementById("<%= txtFirstName.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtLastName.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtDOB.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtStateID.ClientID %>").style.backgroundColor = "";
			}
		}
	}
</script>

Open in new window


Test page :
<%@ Page Title="Page d'accueil" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

<script language="javascript" type="text/javascript">
	window.onload = function() {
		document.getElementById("<%= txtPtID.ClientID %>").onchange = function() {
			if( this.value != "" ) {
				document.getElementById("<%= txtFirstName.ClientID %>").value = "";
				document.getElementById("<%= txtLastName.ClientID %>").value = "";
				document.getElementById("<%= txtDOB.ClientID %>").value = "";
				document.getElementById("<%= txtStateID.ClientID %>").value = "";
				
				document.getElementById("<%= txtFirstName.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtLastName.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtDOB.ClientID %>").removeAttribute("disabled");
				document.getElementById("<%= txtStateID.ClientID %>").removeAttribute("disabled");
				
				document.getElementById("<%= txtFirstName.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtLastName.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtDOB.ClientID %>").style.backgroundColor = "LightGray";
				document.getElementById("<%= txtStateID.ClientID %>").style.backgroundColor = "LightGray";
			}
			else {
				document.getElementById("<%= txtFirstName.ClientID %>").disabled = true;
				document.getElementById("<%= txtLastName.ClientID %>").disabled = true;
				document.getElementById("<%= txtDOB.ClientID %>").disabled = true;
				document.getElementById("<%= txtStateID.ClientID %>").disabled = true;
				
				document.getElementById("<%= txtFirstName.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtLastName.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtDOB.ClientID %>").style.backgroundColor = "";
				document.getElementById("<%= txtStateID.ClientID %>").style.backgroundColor = "";
			}
		}
	}
</script>

</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:TextBox runat="server" ID="txtPtID" /> 
    <asp:TextBox runat="server" ID="txtFirstName" /> 
    <asp:TextBox runat="server" ID="txtLastName" /> 
    <asp:TextBox runat="server" ID="txtDOB" /> 
    <asp:TextBox runat="server" ID="txtStateID" /> 
</asp:Content>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36718714
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question