• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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

I have a  System.Web.UI.HtmlControls.HtmlSelect which is run at server used instead of an asp.net 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

2 Solutions
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:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now