-1

I have a editable table in HTML. Is there any way to get the data from that table into my Servlet page when I submit button?

dur
  • 15,689
  • 25
  • 79
  • 125
Leeza
  • 127
  • 3
  • 15

2 Answers2

0

Before submitting form You have to prevent the form submit using jquery and you have to iterate through each column of the table to get value and set in some hidden field and submit the form through jquery.

ram vinoth
  • 472
  • 4
  • 14
0

The below code iterates through the table value. These values have to be inserted either in some input field inside the form or form some form data in object form and set it in a input field within the form.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#submit").click(function(e){
        e.preventDefault();
        $("#tbody tr td").each(function(){
         alert($(this).text());
        });
        /*
        SET VALUES EITHER IN INPUT FIELD OF FORM NEW FORM DATA AND SET IN A INPUT FIELD.
        
        */
        $("#submit").unbind("click").click();
    });
});
</script>
</head>
<body>
<form method="post" id="form">
<table id="table">
<thead>
<tr>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody id="tbody">
<tr>
<td>Harry</td>
<td>USA</td>
</tr>
<tr>
<td>Jonathan</td>
<td>Germany</td>
</tr>
</tbody>
</table>
<input type="submit" value="submit" id="submit"/>
</form>
</body>
</html>
ram vinoth
  • 472
  • 4
  • 14