Run a javascript function on item click of a list box or a html input select

Posted on 2006-03-22
Last Modified: 2007-12-19
I have a  System.Web.UI.HtmlControls.HtmlSelect which is run at server used instead of an listbox as it has a microsoft bug it does not render attributes.add ,

Now using the Html input control run at server iam able to this

lstBoxUsers.Items(j).Attributes.Add("style", "color:gray")
like setting colurs for individual item

But i need to run a javascript function on item click of the lstboxUser

lstBoxUsers.Items(j).Attributes.Add("Onclick", "return javascriptfunction()")

thanks in advance

Question by:ganeshniceguy
    LVL 10

    Accepted Solution

    I don't think you can do that for items, but you can for the control...
    lstBoxUsers.Attributes.Add("Onclick", "return javascriptfunction()")

    e.g. test this:
    LVL 5

    Assisted Solution

    you should put the - onchange - event onto the <select>, instead of its child.

    then in your javascript function just chk what's the selected value in the SELECT

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now