Mihai Labo
Mihai Labo

Reputation: 1082

Building the Id of CheckBox in Jquery

I have a DropDownList:

 @Html.DropDownList("name", (IEnumerable<SelectListItem>)SlotList[counter], new { id = "slotDDL_" + @item.ResourceID, tid = @item.ResourceID, @class = "slotDDL_ text white" })

and a CheckboxFor:

@Html.CheckBoxFor(modelItem => item.IsSelected, new { @class = "boxcheck_", id = @item.ResourceID })

When executing this:

 $('.slotDDL_').change(function () {
            var resId = $(this).attr("tid");
            IsSelected = 'boxcheck_' + resId;
            alert($('#' + resId).attr("checked"));
      });

I get the following :

alert($(this).attr("tid"))====>505
alert(IsSelected)====> boxcheck_505
alert($('#' + resId).attr("checked"))===>undefined

Question: How can I successfully build the string of my Id ? What am I doing wrong ?

Upvotes: 0

Views: 48

Answers (2)

Snake Eyes
Snake Eyes

Reputation: 16764

Try

@Html.CheckBoxFor(modelItem => item.IsSelected, new { @class = "boxcheck_", id = "@item.ResourceID" })

You missed " for id attribute

Upvotes: 1

Codegiant
Codegiant

Reputation: 2150

put '#' instead of '.'

$('#slotDDL_')

Upvotes: 0

Related Questions