Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a dropdown like tihs

ASP.NET
<asp:DropDownList ID="ddlodem" runat="server"> 



And trying to call javascript like this.
On page load i am writting this line

C#
ddlodem.Attributes.Add("onchange", "return OdemaVisible('<%=ddlOdem.ClientID%>','divOdema','divOedema')")





but it is not working
Posted
Updated 28-Sep-13 1:32am
v3
Comments
Dholakiya Ankit 28-Sep-13 7:33am    
Can you post your javascript function?
satpal 2 5-Oct-13 3:45am    
here is code for javascript function

function OdemaVisible(x, y, z) {
alert("Sat1");
var ddlscanchoice = document.getElementById('<%=ddlOdem.ClientID%>').options[document.getElementById('<%=ddlOdem.ClientID%>').selectedIndex].text;

if (ddlscanchoice == "Yes") {
document.getElementById(y).style.visibility = "visible";
document.getElementById(z).style.visibility = "visible";
}
else {

document.getElementById(y).style.visibility = "hidden";
document.getElementById(z).style.visibility = "hidden";

}
}
Dholakiya Ankit 5-Oct-13 6:20am    
Don't use client id do like this inspect element in your browser and get client id copied and put it in to code then see the result and instead onchange use onclick event....and then tell me ......
-ank
Harshil_Raval 28-Sep-13 7:45am    
What is not working? Are you not able to call that function on change event? or function is not working as your need?
satpal 2 5-Oct-13 3:45am    
here is code for javascript function

function OdemaVisible(x, y, z) {
alert("Sat1");
var ddlscanchoice = document.getElementById('<%=ddlOdem.ClientID%>').options[document.getElementById('<%=ddlOdem.ClientID%>').selectedIndex].text;

if (ddlscanchoice == "Yes") {
document.getElementById(y).style.visibility = "visible";
document.getElementById(z).style.visibility = "visible";
}
else {

document.getElementById(y).style.visibility = "hidden";
document.getElementById(z).style.visibility = "hidden";

}
}

Here this'll work:

C#
ddlOdem.Attributes["onchange"] ="OdemaVisible('"+ddlOdem.ClientID+"','divOdema','divOedema')";


Cheers

Goodluck
 
Share this answer
 
Comments
satpal 2 28-Sep-13 6:18am    
Asif ..it is still not working
Azee 28-Sep-13 11:20am    
I replicated your scenario and the JavaScript function does get called. There could be something wrong in your function. Debug your JavaScript function. Try alerts from line to line. If its not your function that post your complete code. I'll take a look.
satpal 2 5-Oct-13 3:38am    
here is code for javascript function

function OdemaVisible(x, y, z) {
alert("Sat1");
var ddlscanchoice = document.getElementById('<%=ddlOdem.ClientID%>').options[document.getElementById('<%=ddlOdem.ClientID%>').selectedIndex].text;

if (ddlscanchoice == "Yes") {
document.getElementById(y).style.visibility = "visible";
document.getElementById(z).style.visibility = "visible";
}
else {

document.getElementById(y).style.visibility = "hidden";
document.getElementById(z).style.visibility = "hidden";

}
}
You need to use RegsiterClientScipt. This will help you to call javascript function either before page load or after page load.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900