Reputation: 2711
I have a loop in my MVC-project whick generates a list of open-timeslots:
foreach (var item in Model.LedigaTider)
{
<a id="@item">
<div class="table-time" id="@item.ToShortTimeString()">
@item.ToShortTimeString() - @item.AddMinutes(ViewBag.BehTid).ToShortTimeString()
</div>
</a>
The user is suppose to click on one of the time-slots and I need to store the value of that timeslot in an input-textbox...I´ve been trying som different Js-functions but they have failed due to the fact that its beeing executed within the foreach-loop. Thankful for any suggestions.
Upvotes: 0
Views: 54
Reputation: 62488
you can do like this:
assuming you have a textbox:
<input type="text" id="txtBox"/>
Jquery code:
$('.table-time').click(function(){
$('input#txtBox').val($(this).html());
})
Upvotes: 1