Reputation: 79
I have an index page (index.jsp
) that prints out the ID number of people stored in newtable
. This works ok.
index.jsp
try {
out.println("Connection Successful...");
mystmt = myConn.createStatement();
myrs = mystmt.executeQuery("SELECT * FROM records.newtable");
while (myrs.next())
out.println("</br>"+myrs.getInt("ID")+"<a href=\"editrecord.jsp\"> Edit </a>);
}
I have added an edit link that appears after each ID returned. The edit link is pointing at editrecord.jsp
. I would like to be able to update the firstname and lastname of the ID I selected with the original value displayed in the input box. Has anyone any ideas? I have no issues connecting to the database. Cheers.
editform.jsp
<p>First name: <br>
<input name="fn" value= <%out.println(myrs.getString("FIRSTNAME"));%>></p>
<p>Last name: <br>
<input name="ln" value=<%out.println(myrs.getString("LASTNAME"));%>></p>
<br/><input type="submit" value="Submit">
Upvotes: 0
Views: 407
Reputation: 12391
You need to make an ajax call based on the click.
Go and fetch the row and fill the UI fields based on the data received.
onclick="fillFields(pass_id_here)";
JS (just to get an idea of how it will work):
function fillFields(id){
$.ajax({
type: "get",
url: 'URL THAT CAN RETURN JSON OF THE RECORD ROW',
data: {id:id},
success: function(response){
var resultData = JSON.parse(response);
$("#firstName").val(resultData.firstName);
$("#lastName").val(resultData.lastName);
});
}
OR maybe:
On click you can reload the page and send the row data on the view and fill the fields.
Upvotes: 1