I have added an onchange event to the DropDownlistFor which is working fine, I think.
I am adding a new dropdownlistfor into the DOM so that I can have multiple selected items (note the multiple dropdowns contain different data sources).
When the dropdowns are created, the id's are all different, but work along the lines of
newObject_XX__dropDownName
Where XX is an incremental number starting at 0, and are added to the DOM using the following:
$(XX).change(function(){ FunkyTest(this); });
Where XX is newObject_XX__dropDownName from above.
And the javascript function FunckyTest is as follows.
function FunkyTest(event)
{
var e = event.id;
var elem = "select#" + e + " option.selected"
var t = $(elem).text();
var v = $(elem).val();
alert(q);
}
I am trying to get the currently selected data from the dropdown.
$("select#newObject_XX__dropDownName option:selected").text();
This is the method shown by the jQuery website, but when I replace the "select#newObject_XX__dropDownName option:selected" for the var elem within FunkyTest it does not work.
Don't worry all.
Found solution.....
var t = $("select#" + event.id + " option:selected").text()
var v = $("select#" + event.id + " option:selected").val()
Does the job.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments