I've been trying to find three inputs (type=text) which were added dynamically using jQuery. I've tried to use .closest(), .parents(), .find(), and .children(), but I failed.
I also tried with document.getElementsByName, but it does not return the correct value if I create more than one group of inputs (which can be added dynamically, as I said before).
My code is the following:
function update(username, row) {
affiliation_val = $(document.getElementsByName('affiliation')).val(),
comments_val = $(document.getElementsByName('comments')).val(),
role_val = $(document.getElementsByName('role')).val();
//the search above does not work when I add multiple inputs… it returns only the first three inputs
console.log( $(row).closest(“input”) ); //one of my attempts... I also did using a combination of parents("tbody") and children("input"), for example... and many others
}
function format(d) {
var message1 = '<table cellpadding="8" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td class="text-right"><b>User ID:</b></td>'+
'<td class="text-left"> '+username+'</td>'+
'</tr>'+
'<tr>'+
'<td class="text-right"><b>Password last set:</b></td>'+
'<td class="text-left"> '+d.pwd_last_set+'</td>'+
'</tr>'+
'<tr>'+
'<td class="text-right"><b>Uid number:</b></td>'+
'<td class="text-left"> '+d.uid+'</td>'+
'</tr>'+
'<tr>'+
'<td class="text-right"><b>Email:</b></td>'+
'<td class="text-left"> '+d.email+'</td>'+
'</tr>'+
split_projects(d.projects_name, d.projects_role),
message2 = '<tr>'+
'<td class="text-right"><b>Affiliation:</b></td>'+
'<td class="text-left"><input type="text" name="affiliation" value="'+d.affiliation+'" '+readonly+' /></td>'+
'</tr>'+
'<tr>'+
'<td class="text-right"><b>Comments:</b></td>'+
'<td class="text-left"> <input type="text" name="comments" value="'+d.comment+'" '+readonly+' /></td>'+
'</tr>'+
'<tr>'+
'<td class="text-right"><b>Role:</b></td>'+
'<td class="text-left"><input type="text" name="role" value="'+d.role+'" '+readonly+' /></td>'+
'</tr>',
message3 = show_inconsistency(inconsistent)+
show_miss_uid(miss_uid)+
'<tr>'+
'<td> </td>' +
'<td>'+
'<button type="button" class="btn btn-default" onclick="sendMail(\'' +username+ '\'); return false">' +
'<span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Request change of permission' +
'</button> <br/><br/> ' +
'</td>' +
'</tr>' +
'</table>',
button = '<tr><td> </td><td><button class="btn btn-default" onclick="update(\''+username+'\', this)">Update</button</td></tr>';
return message1+message2+button+message3;
}
Any help would be highly appreciate...