The problem is that you are binding onchange
event to the <option>
instead of binding it to the <select>
element. The code should look like:
drp.Items.Add(new ListItem("Ladies T-shirt", "1"));
drp.Items.Add(new ListItem("Mens T-shirt", "2"));
string script = @"
function changeImg(drp)
{
var item = drp.value;
switch(item)
{
";
foreach (ListItem item in drp.Items)
{
script += "case '" + item.Value + "': alert('Selected value' + item);break;";
// Here should be your jQuery('.fancyboxProductImg').html() call - instead of alert
}
script += "}}";
ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "myscript", script, true);
drp.Attributes.Add("onchange", "changeImg(this);");