There's a lot of other threads on this topic but none of them solve my issue. I'm trying to get the value from a input field which I just inserted. I insert my input box using this line of javascript:
processName.innerHTML = '<input type="text" id="ProcessNameChange" value="' + oldName + '" >';`
Then I try to access it using:
var newName = $(this).closest("#ProcessNameChange").val();
Both of these are wrapped in an event, a button click event. Below is the entire function if you'd like all of it. Also, if you have a better way of coding anything I wrote, feel free to share it.
$('.Edit').click(function () {
if ($(this).attr("id") != "submitUpdate") {
$(this).attr("id", "submitUpdate");
$(this).text("Submit");
var closestTR = $(this).closest("tr");
var processName = closestTR.children()[2];
var processDescription = closestTR.children()[3];
var processID = closestTR.children()[4];
var oldName = processName.innerHTML;
var oldDesc = processDescription.innerHTML;
processName.innerHTML = '<input type="text" id="ProcessNameChange" value="' + oldName + '" >';
processDescription.innerHTML = '<input type="text" id="ProcessDescChange" value="' + oldDesc + '" > ';
submitButtonClick();
} else {
var newName = $(this).closest("#ProcessNameChange").val();
var newDesc = $(this).closest("#ProcessDescChange").val();
var processID = $(this).closest("tr").children()[4];
}
--> Related to Comments: The HTML for the input box always stays as shown below: It's all made via a repeater than modified with javascript.
<tr>
<td class="grid-main-detail"></td>
<td>
<input id="ProcessNameChange" type="text" value="PNameOld">
</td>
<td>
<input id="ProcessDescChange" type="text" value="PDescOld">
</td>
<td>
<td>3547556300824952452</td>
<td>Me </td>
<td>7/19/2013 2:32:48 PM</td>
</tr>
Thanks!