Marius Vasile

Marius Vasile

  • 590
  • 1.9k
  • 149k

jquery to loop through textboxes and select data

Aug 9 2021 7:05 AM

I have a form with checkboxes, generated with a foreach loop and I want to populate input based on checkbox select. View below

@foreach (var item in Model.RCACategoryMains)
{
    count = count + 1;
    <div id="DivRows" class="row no-gutters mb-1">
        <div class="col-md-1">
            <span class="form-control">@Model.RCACategoryMains[i].IdRCAM</span>
        </div>
        <div class="col-md-4">
            <span id="mainData[@i]" class="form-control" asp-for="RCACategoryList[i].RCACatName" name="selectedCategory[@i]">@Model.RCACategoryMains[i].Category"</span>
            <input id="inputData[@i]" class="form-control bg-white" asp-for="RCACategoryList[i].RCACatName" name="selectedCategory[@i]" />
        </div>
        <div class="col-md-2 text-center">
            <input id="selectData[@i]" type="checkbox" data-toggle="toggle" data-on="Yes" data-off="No" data-width="200" data-height="40" data-onstyle="success" data-offstyle="danger">
        </div>
    </div>
    i++;
}

How do I populate input (inputData) with (mainData) on (selectData) check using jquery?


Answers (3)