index.xml
<Alloy>
<Window class="container">
</Window>
</Alloy>
index.js
function btnClickedHandler(e){
alert(nameTi.text);
alert($.index.nameTi);
}
function addContent(){
var showBtn = Ti.UI.createButton({
id: "showButton",
title:"Show Text",
top: 10,
});
var nameTi = Ti.UI.createTextField({
id:"displayText",
textFieldId: 'displayText',
width: 50
});
showBtn.addEventListener("click", btnClickedHandler);
$.index.add(nameTi);
$.index.add(showBtn);
}
$.index.open();
addContent();
Any suggestions to access dynamically added text input. One way could be definitely by storing instance in global variable. But can be done using id like $("#instanceId")
Try this:
function addContent(){
var showBtn = Ti.UI.createButton({
id: "showButton",
title:"Show Text",
top: 10,
});
var nameTi = Ti.UI.createTextField({
id:"displayText",
textFieldId: 'displayText',
width: 50
});
showBtn.addEventListener("click", function(){
alert(nameTi.text);
alert($.index.nameTi);
}
});
$.index.add(nameTi);
$.index.add(showBtn);
}
$.index.open();
addContent();