I have a web page where users can upload pdfs. When users have uploaded for instance 3 pdfs, then three textarea and buttons are generated so that they can submit titles for the pdfs. My problem is I do not know how to get access to the text in the textarea of these dynamically generated texareas as i hope to also assign those titles to the uploaded pdfs. When any of the button are pressed, my submitTitle() function has no idea which button was pressed, and I do not know how to figure this one out. I have a scope problem and don't know how to sort this. Please can someone advise?
Here is my code thus far:
function completeHandler(event){
// convert JSON text to a JSON object
var jsonObject = JSON.parse(event.target.responseText);
_("status").innerHTML = jsonObject.succeed[0].name;
// Creating a form dynamically.
// Allow user to copy/paste the title of the pdf.
var succeedList = jsonObject.succeed;
console.log(succeedList);
for( i=0; i<succeedList.length; i++){
var div_forTextArea = document.createElement("DIV");
div_forTextArea.setAttribute('class', 'dyn_div');
var heading = document.createElement("h6");
heading.innerHTML = jsonObject.succeed[i].name;
div_forTextArea.appendChild(heading);
var textarea = document.createElement("TEXTAREA");
var txtarea_id = 'txt_'+i;
textarea.innerHTML="Enter title of pdf here...";
textarea.setAttribute('id', 'txtArea_'+i);
div_forTextArea.appendChild(textarea);
console.log(textarea);
var subm_btn = document.createElement("INPUT");
subm_btn.setAttribute('type','submit');
subm_btn.setAttribute('id', 'btn_'+i);
subm_btn.setAttribute('value', "submit title");
subm_btn.setAttribute('onclick', 'submitTitle()');
console.log(subm_btn);
div_forTextArea.appendChild(subm_btn);
document.getElementById('out_box').appendChild(div_forTextArea);
}
}
function submitTitle(){
//?????
}