iam developing an small Java EE application and i have created a servelt to enter student data to the database. i have displayed student data in another servlet using HTML table.in HTML table i have added a button to Update student data as the first column.that means in each row there is a update button.My problem is i want to get the corresponding second column value when user clicks on any row in order to update the student data.In second column i have student ID. Below is my code
Calling myFunction();
out.println("<td><button type='button' onclick='myFunction()'>Update</button></td>");
MyJavascriptCode
out.println("<script>");
out.println("function myFunction()");
out.println("{");
out.println("var Row = document.getElementById('trid');");
out.println("var Cells = Row.getElementsByTagName('td');");
//call update using EntityManager
out.println();
out.println("}");
out.println("</script>");
My second question is how can i access Row and Cells variables? example: I want to print Row and Cells values using document.write();
Thanks in advance
I suppose you have some result list. For example, List<Student>
. In this case it will be:
out.println("<td><button type='button'
onclick='myFunction("+student.getId()+")'>Update</button></td>");
So you can pass student id into your javascript function.
But it would be better to display data using jstl and <c:forEach>
tag.
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.