How do I call onclick when the user clicks in asp.mvc 5. The below code doesnt work
@Html.ListBoxFor(m => Model.DepDashTaskLists[i].BusinessRuleQuestion1Answer, new MultiSelectList(slh.GetRegistrationAnswerLookup(Model.DepDashTaskLists[i].BusinessRuleQuestion1), "Value", "Text", Model.DepDashTaskLists[i].BusinessRuleAnswers), new { @onclick="somefunction()", @id = "RuleQuestionListBoxAnswer", @class = "listbox" })
Have some javascript
which listens to the click event on the listbox
and get the item text and set as the value of the other textbox
@Html.ListBoxFor(x => x.ItemId, new MultiSelectList(Model.ListOfItems, "Text", "Value", Model.ItemId), new { size = 6, id = "itemsList", OnChange = "showText" })
$(function(){
$("#ItemId option").click(function () {
var _this = $(this);
$("#txtItem").val($(_this).text());
});
});
Working sample: http://jsfiddle.net/w4sxw/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.