Insert text into a text field

I have a button in my app that calculates a date string (ie: 2013-09-19).

I can get this to print to the screen in the simulator, but when I try and insert it to a text field, the app crashes.

[lua]local widget = require (“widget”)

local function handleButtonEvent( event )
local phase = event.phase

if “began” == phase then
local date = os.date( “*t” )
local datetext=date.year … " " … date.month … " " … date.day
datefield.text= date.year … " " … date.month … " " … date.day
end
end

local DateButton=widget.newButton
{

left=10,
top=40,
label=“Add Current Date”,
fontSize=18,
labelColor={default={0,0,0}, over ={255, 255, 255}},
onEvent=handleButtonEvent
}

DateButton.baseLabel=“Date”

local datefieldlabel = display.newText (“Date:”, 10, 150, native.systemFont, 14)
local datefield = native.newTextField(50, 150, 100, 20)
datefield.isEditable=true
local datefieldhelp = display.newText (“Format yyyy-mm-dd”, 170, 150, native.systemFont, 14)

local attendancefieldlabel = display.newText (“Attendees:”, 10, 250, native.systemFont, 14)
local attendancefield = native.newTextField(50, 250, 100, 20)
attendancefield.isEditable=true
[/lua]

If you need help with a crash then please post the error message as well. You might have a scoping issue.  Try placing the datefield text above the handleButtonEvent, or predeclare it at the top of the code.

stack traceback:

    [C]: ?

    /Users/seandzafovic/Desktop/Outreach Event/main.lua:10: in function ‘_onEvent’

    ?: in function ‘?’

    ?: in function <?:1052>

    ?: in function <?:218>

I tried moving the datefield above the handle button event and it worked correctly.

Thanks.

If you need help with a crash then please post the error message as well. You might have a scoping issue.  Try placing the datefield text above the handleButtonEvent, or predeclare it at the top of the code.

stack traceback:

    [C]: ?

    /Users/seandzafovic/Desktop/Outreach Event/main.lua:10: in function ‘_onEvent’

    ?: in function ‘?’

    ?: in function <?:1052>

    ?: in function <?:218>

I tried moving the datefield above the handle button event and it worked correctly.

Thanks.