Created
April 16, 2015 13:00
-
-
Save rajubd49/c6e0a0dd6b221986b1b1 to your computer and use it in GitHub Desktop.
How to evaluate mathematical expression - Appcelerator Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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