Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a Drop Down List called "drop_category" like:

-Category1
-Category2
-Category3
-Category4
-Add new category

and i want the web will open a popup when user select item "Add new category"

i tried
drop_category.Items.FindByText("Add new category").Attributes.Add("onfocus", "newCate()");

--
 function newCate() {
        window.open('Category_Manage.aspx', null, 'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');
        return false;

but it not work. How i can do it?

I would really appreciate your help
Posted
Updated 1-Mar-12 18:45pm
v2

1 solution

Use the onChange event of thr drop_category and use the selectedIndex to find if its the selected item.

C#
drop_category.Attributes.Add("onChange", "newCate();");


in the code behind and in the js

JavaScript
function newCate() {
var e = document.getElementById('ctl00_<panelname>_drop_category');
    if (e.options[e.selectedIndex].value == '0')
        window.open('Category_Manage.aspx', null, 'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');
    return false;
}


Replace the value with whatever value you have. Do Note that your control name in javascript may be different. If you have your javascript as inline you can use the ClientId to retrieve the drop down's name when it is rendered in html. Like this:

JavaScript
document.getElementById('<%= this.drop_category.ClientID %>');
 
Share this answer
 
v2
Comments
summerrain_90 2-Mar-12 8:49am    
thank you so much xD

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