In a page there is dropdown list with the name of the
cities like Bangalore,Pune,Chennai,Other and a text box
that would enable the user to enter the name of the city if
other is selected. How to enable validation on the text box
if other is selected
Answer Posted / sai krishna
In aspx page
<asp:DropDownList ID="DropDownList1" runat="server"
Width="176px">
<asp:ListItem>Pune</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
<asp:ListItem>Hyderabad</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>
<script language="javascript" type="text/javascript">
var other1 = window.document.getElementById("TextBox2");
other1.disabled = true;
function ValidateOtherCity()
{
var other = window.document.getElementById
("DropDownList1");
var other2 = window.document.getElementById
("TextBox2");
if(other.value == 'Other')
{
other2.disabled = false;
}
else
{
other2.disabled = true;
}
}
</script>
In aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Attributes.Add
("OnChange", "javascript:ValidateOtherCity();");
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
How do you remove duplicates without using remove duplicate stage?
Why mvc is faster than asp.net? : Asp.Net MVC
How can we call webservices in Banking Applications? and where we are using it?
Where do the cookie state and session state information be stored?
What is the use of session state and application state and difference between them?
How do we sort the data from a dataset?
i want the asp.net technical questions and answeres
Can we have multiple master pages in asp net?
What is tracing? Where is it used?
What is application variable?
Explain the code Access Security (CAS) in .net Framework?
What is advantage of code behind coding in ASP.NET?
What is the meaning of TestApi?
What are the advantages of Web API?
What is the use of session?