• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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