Tuesday, May 13, 2008

Client side script for selected index changed of Drop Dwon list

function ddlAcquirerSelectedIndexChanged()
{
var ListBox1Id = '<%= ddlAcquirer.ClientID %>';
var TextBox1Id = '<%=txtAcquirer.ClientID %>';
var lblId='<%=lblAcquirer1.ClientID %>';
if (document.getElementById(ListBox1Id).selectedIndex >= 0)
{
var selectedIndex = document.getElementById(ListBox1Id).selectedIndex;
if(document.getElementById(ListBox1Id).options[selectedIndex].value=='Barclaycard')
{
document.getElementById(TextBox1Id).disabled=true;
document.getElementById(lblId).disabled=true;
document.getElementById('<%=lblBarclayardMerchantNo.ClientID %>').disabled=false;
document.getElementById('<%=txtBarclayardMerchantNo.ClientID %>').disabled=false;
}
else
{
document.getElementById(TextBox1Id).disabled=false;
document.getElementById(lblId).disabled=false;
document.getElementById('<%=lblBarclayardMerchantNo.ClientID %>').disabled=true;
document.getElementById('<%=txtBarclayardMerchantNo.ClientID %>').disabled=true;
}
}

And in Page load event in code behind

ddlAcquirer.Attributes.Add("onchange", "ddlAcquirerSelectedIndexChanged();")

No comments: