Skip to content

Instantly share code, notes, and snippets.

@rajubd49
Created April 16, 2015 13:00
Show Gist options
  • Save rajubd49/c6e0a0dd6b221986b1b1 to your computer and use it in GitHub Desktop.
Save rajubd49/c6e0a0dd6b221986b1b1 to your computer and use it in GitHub Desktop.
How to evaluate mathematical expression - Appcelerator Titanium
var win = Ti.UI.createWindow({backgroundColor : 'white'});
var txtFld = Ti.UI.createTextField({
height : 40,
width : 120,
backgroundColor : 'gray'
});
win.add(txtFld);
var numLbl = Ti.UI.createLabel({
top : 20,
height : 40,
width : 120,
borderColor : 'gray',
color:'black'
});
win.add(numLbl);
txtFld.addEventListener('change', function(e) {
try{
var evaluatedValue = eval(this.value);
}catch(e){
Ti.API.info('error');
}
numLbl.text = evaluatedValue;
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment