Reputation: 1225
I need to be able to store and retrieve an additional ID when creating a dropdown list box. Currently my option values are -
<option value="@x.Id" description="@x.Description" selected="selected">@x.PromotionCode</option>
and then I am able to retrieve the value using -
$("#discount-selection").change(function () {
alert ($(this).val())
});
What other element in the option tag can I use and how do I retrieve it?
Upvotes: 0
Views: 85
Reputation: 1414
you can use the data-* introduced in HTML5 for storing custom data private to the page or application
Upvotes: 0
Reputation: 3389
You can you HTML5 data attributes to get anything you like from an element for example.
<option value="@x.Id" data-description="@x.Description" data-index="0" selected="selected">@x.PromotionCode</option>
$("#discount-selection").change(function ()
{
var selected = $(this).find(':selected');
selected.data('description'); // returns @x.Description
selected.data('index'); // returns 0
});
Upvotes: 1