I have a list of drop down lists populated form a database(using ASP.NET).
These drop down lists are ASP Controls, so selecting them by ID is not feasible.
They are named as such:
DD_Manufacturer1
DD_Manufacturer2
DD_Manufacturer3
These ASP.NET DropDown lists have a class that is the same as their name(EXAMPLE: DD_Manufacturer1’s class is =”DD_Manufacturer1″)
I am using a cascading dropdrop(We will call the ID of the first selection input MyList1).After a user selects an option from MyList1, one of my ASP DropDowns becomes visible(Example: I chose Manufacturer1 in MyList1 and DD_Manufacuturer1 becomes visible)
Here is how it SHOULD work:
Manufacturer1 is chosen from MyList1
The selected value of MyList1 is passed on to hidden form field called dvMake
DD_Manufacturer1 becomes visible(This is an ASP.NET CONTROL)
User selects an option in DD_Manfacturer1
Selected value of DD_Manufacturer1 is passed on to hiddenfield called hidden-dvModel
Now, I am wanting to pass the selection of DD_Manufacturer1 onto a hiddenfield so it is easier to manipulate.
Here is my code so far:
function onModelChange() {
$("#hidden-dvModel").remove(); //Removes Hidden Field if it already exists
var dvMake = $("#hidden-dvMake").val(); //Get Make Value
var ActiveMake = $("."+dvMake+""); //Derive Active DD List form Selected Make
var ActiveMakeList = "DD_" + ActiveMake.attr('class') + "";
alert(ActiveMakeList);//Succesfully returns DD_Manufacturer1
var SelectModel = ?
$('#phSelect').append("<input type='hidden' id='hidden-dvModel' value='" + SelectModel + "' />");
}
I thought the best way to do this would to just preform a wildcard selection and check if it is visible, then get its selected value.
So how would I preform a wildcard selection of any element whoose ID begins with “DD”, that is visible, and then get the selected value of it?
var SelectModel = $(“[id^=DD_]:visible option:selected”).val(); returns “undefined”
Try using
That’s because
ASP.NET WebFormsusually prepends IDs with the ID of content place holders, giving your elements fugly names likectl_ContentPlaceHolder01_DD_Manufacturer1.