I've done some research regarding on how to replace/change the original html button to another. But neither the ways are working.
Here are my codes:
Javascript:
var editBtn = "editBtn" + id; //in order to get the id of the edit button
var cSave = document.getElementById(editBtn);
cSave.innerHTML = "<td><button id='saveBtn' onclick='saveChange(" + id + ");' >Save</button></td>";
The code above is just adding a button inside the existing button.
HTML:
<table>
<td>
<%
out.println("<button id='editBtn" + mc.getId() + "' onclick='editMC(this.id);'>Edit</button>");
%>
</td>
</table>
The mc.getId() is a method to get the "id".
The latest approach that I've tried is mentioned below, but it's not working:
document.getElementById(editBtn).onclick = function() {saveChange(id)};
And:
$(document).ready(function () {
$("#editBtn").replaceWith("<td><button id='saveBtn' onclick='saveChange(" + mcId + ");' >Save</button></td>");
});
Anyhow I can do to change the edit button to save button while onclick() is performed?
document.getElementById(editBtn), IS editBtn Variable ? , if not then make itdocument.getElementById("editBtn")#editBtnis not the ID of the button, it's calling a function that adds something to the ID.TDelement which is wrong. Take a look at my demo.