Search code examples
buttontextareatitaniumappcelerator

how to pass textarea value to javascript function on button click


I would like make that when user inputs any data on textarea, my Calculate button makes any calculation. At this point, how can I hold the data which is given by user in order to send it to Calculator button? Anyone know how it can be?

Here is the textarea, user gives any data

var textAreaHeight = Ti.UI.createTextArea({
    borderWidth: 2,
    borderColor: '#bbb',
    borderRadius: 5,
    color: '#888',
    font: {fontSize:20, 
    fontWeight:'bold'},
    keyboardType: Ti.UI.KEYBOARD_NUMBER_PAD,
    returnKeyType: Ti.UI.RETURNKEY_GO,
    left:200,
    top: 300,
    width: 125, 
    height : 40
});

Here is my button which makes any assumpitons

var CalculatorButton = Ti.UI.createButton({
    title:'Calculate',
    top:475,
    width:400,
    height:90,
    left:75
});

Solution

  • You can do it like this

      var CalculatorButton = Ti.UI.createButton({
            title:'Calculate',
            top:475,
            width:400,
            height:90,
            left:75
            });
    
    
          CalculatorButton.addEventListener('click',function(e){
            var result=textAreaHeight.value
            alert(result);
            });
    

    Thanks