0

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

4

1 回答 1

0

我想你有一些结果列表。例如,List<Student>。在这种情况下,它将是:

    out.println("<td><button type='button'
       onclick='myFunction("+student.getId()+")'>Update</button></td>");

因此,您可以将学生 ID 传递到您的 javascript 函数中。
但是最好使用jstl和<c:forEach>tag来显示数据。

于 2013-08-01T23:32:13.933 回答