Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

function not defined as error

Hi,

I am beginner for titanium development application.
I am creating an application to convert temperature
from degree to Fahrenheit.
when i click the button i want to read value from textbox1(f1)
and do the calculation and display the result in textbox3(f3)
.
Please do the needful.

createUI();

function createUI(){
Titanium.UI.setBackgroundColor('#000');

var win = Titanium.UI.createWindow({
    title: 'Without scrollView',
});

var l = Titanium.UI.createLabel({
    color: '#fff',
    text: 'Labels and fields.',
    top: 0,
    left: 0,
    width: 'auto',
    height: 'auto'
});
win.add(l);

var l1 = Titanium.UI.createLabel({
    color: '#fff',
    text: 'Label 1:',
    top: 70,
    left: 30,
    width: 100,
    height: 'auto'
});
win.add(l1);

var f1 = Titanium.UI.createTextField({
    hintText: 'Field 1',
    height: 35,
    top: 95,
    left: 30,
    right: 30,
    borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
    keyboardType: Titanium.UI.KEYBOARD_PHONE_PAD
});    
win.add(f1);

var l2 = Titanium.UI.createLabel({
    color: '#fff',
    text: 'Label 2:',
    top: 135,
    left: 30,
    width: 100,
    height: 'auto'
});
win.add(l2);

var f2 = Titanium.UI.createTextField({
    hintText: 'Field 2',
    height: 35,
    top: 160,
    left: 30,
    right: 30,
    borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
    keyboardType: Titanium.UI.KEYBOARD_PHONE_PAD
});
win.add(f2);

var l3 = Titanium.UI.createLabel({
    color: '#fff',
    text: 'Label 3:',
    top: 205,
    left: 30,
    width: 200,
    height: 'auto'
});
win.add(l3);

var f3 = Titanium.UI.createTextField({
    hintText: 'Field 3',
    height: 35,
    top: 230,
    left: 30,
    right: 30,
    borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
    keyboardType: Titanium.UI.KEYBOARD_PHONE_PAD
});    
win.add(f3);

var aButton = Titanium.UI.createButton({
    title: 'Submit',
    top: 290,
    height: 30,
    width: 200,
    borderRadius:5
});    
aButton.addEventListener('click', aButtonClicked);
win.add(aButton);

win.open();

}
function aButtonClicked() {

f3=(f1-32)*5/9  please guide what should be the code here to calculate.

}

— asked October 1st 2010 by pavan kumar
0 Comments

1 Answer

  • Accepted Answer

    function aButtonClicked() {
    
    f3.value=(f1.value-32)*5/9;
    
    }
    

    This is not tested and I am not familiar with the calculation but you may need to re-arrange the multiplication and division but that is basically what you need… take a look at the apis and a tutorial on javascript to get further.

    — answered October 1st 2010 by Jez Manser
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.