Titanium Community Questions & Answer Archive

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

Textfield.value = null - even after filling it in

Ok strange error here. I have been using Titanium for sometime now and this is the first time i have ever seen this happen.

I have a Textfield in a window that asks me to input a username. When I click done it my code should process that username.

But at present i have a bug, in where the value of that textfield is not being retrieved.

    var username = Ti.UI.createTextField({
    right:10,
    left:10,
    value:null,
    hintText:"Username",
        borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
});

var un = username.value;

save.addEventListener('click', function()
{    

    alert(un);


});

I know this should work as I have used it many times before. But this is the first time i have had this bug? anyone else had this before?

— asked November 22nd 2010 by Chris Johnson
  • addeventlistener
  • bug
  • error
  • iphone
  • textfield
  • value
0 Comments

1 Answer

  • Accepted Answer

    Hi Chris

    You simply need to move the un variable inside the eventListener. As you are, you are setting it to the initial username.value contents.

    For example,

    save.addEventListener('click', function()
    {   
        var un = username.value; 
        alert(un);
    });
    

    Hope this helps

    — answered November 22nd 2010 by Paul Dowsett
    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.