<pre><form method="post" asp-controller="Jobs"> <div class="row"> @for (int i = 0; i < Model.Questions.Count; i++) { <div class="col-12"> <p class="fw-bold"> @Model.Questions[i].Question </p> @for (int j = 0; j < @Model.Questions[i].Answers.Count; j++) { <div class="form-check"> <input type="radio" class="form-check-input" asp-for="@Model.Questions[i].SelectedAnswerId" id="@Model.Questions[i].Answers[j].Id" name=" @Model.Questions[i].Id" onchange="filldata()" value="@Model.Questions[i].Answers[j].Id"> <input value="55" asp-for="@Model.Questions[i].SelectedAnswerId" hidden /> <label class="form-check-label" for="@Model.Questions[i].Answers[j].Id"> @Model.Questions[i].Answers[j].Answer </label> </div> } </div> } <div class="col-12"> <div class="d-flex justify-content-center"> <button type="submit" asp-action="SaveExam" class="btn btn-primary px-4 py-2 fw-bold">Submit</button> </div> </div> </div> </form> </div> <script type='text/javascript'> function checkButton() { var getSelectedValue = document.querySelector( 'input[name="@Model.Questions[i].Answers[j].Id"]:checked'); if (getSelectedValue != null) { document.getElementById("disp").innerHTML = getSelectedValue.value + " is selected"; } else { document.getElementById("error").innerHTML = "*You have not selected any "; } } </script>
<pre> <form method="post" asp-controller="Jobs"> <div class="row"> @for (int i = 0; i < Model.Questions.Count; i++) { <div class="col-12"> <p class="fw-bold"> @Model.Questions[i].Question </p> <h3 id="@('d' + i)" style="color:green"> </h3> <h4 id="@('E' + i)" style="color:red"> </h4> @for (int j = 0; j < @Model.Questions[i].Answers.Count; j++) { <div class="form-check"> <input type="radio" class="form-check-input" asp-for="@Model.Questions[i].SelectedAnswerId" id="@('A' + Model.Questions[i].Answers[j].Id)" name="@('D' + Model.Questions[i].Id)" onchange="filldata(this.value)" value="@Model.Questions[i].Answers[j].Id" /> <input id="@('B' + Model.Questions[i].SelectedAnswerId)" asp-for="@Model.Questions[i].SelectedAnswerId" hidden /> <label class="form-check-label" for="@Model.Questions[i].Answers[j].Id"> @Model.Questions[i].Answers[j].Answer </label> </div> <script type='text/javascript'> function filldata(val) { document.getElementById("@('B' + Model.Questions[i].SelectedAnswerId)").value = val } </script> } </div> } <div class="col-12"> <div class="d-flex justify-content-center"> <button type="button" onclick=" checkButton()"> checkButton </button> <button type="submit" asp-action="SaveExam" class="btn btn-primary px-4 py-2 fw-bold">Submit</button> </div> </div> </div> </form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)