function not defined as error

You must Login before you can answer or comment on any questions.

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.

}

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.

Your Answer

Think you can help? Login to answer this question!