I recently developed a school website where teachers can input students' marks. Currently, I have organized the project into three main files:
The first file is designed to showcase every student's name based on their subject and course.
<table class="check">
<tr class="arrow">
<th>Student</th>
<th>Add Mark</th>
</tr>
@foreach(var users in user){
<tr class="arrow">
<td>@users.Nombre @users.Apellido</td>
<td>
<form method="post">
<input type="text" id="user" style="display: none" name="user" @Validation.For("nombre") value="@users.UserId" />
<input type="text" id="galleryId" style="display: none" name="galleryId" @Validation.For("nombre") value="@galleryId" />
<input type="text" id="note" name="button2" name="note" @Validation.For("nombre") />
<input type="button" value="Ready" title="Ready" onclick="loco(document.getElementById('user').value, document.getElementById('galleryId').value, document.getElementById('note').value)" />
</form>
</td>
</tr>
}
</table>
On this page, you will notice that I utilized foreach
to display each student's name alongside an input textbox for the teacher to enter the mark of a specific student. The form is included within the foreach
loop for this purpose.
The following file focuses on implementing ajax functionality:
function loco(user, gallery, note) {
var xmlhttp;
var user = document.getElementById("user").value;
var galleryid = document.getElementById("galleryId").value;
var note = document.getElementById("note").value;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "/Marks/add1/" + gallery + "/" + user + "/" + note, true);
xmlhttp.send();
}
Lastly, we have a page dedicated to inserting marks into the database without presenting any additional visual components.
@{
var db2 = Database.Open("ica");
var user = UrlData[1];
var galleryId = UrlData[0];
var note = UrlData[2].AsInt();
db2.Execute("INSERT INTO Notas (Nota, UserId, Sub_Id) VALUES (@0, @1, @2)", note, user, galleryId);
}
However, I am facing an issue where the ajax function tends to send values only for the first student rather than the subsequent ones. Upon clicking the submit button for the second or third student, it consistently sends the mark of the initial student. Any insights into resolving this matter would be greatly appreciated.