How to save the value of a text field?

Hi guys i’m trying to save the value of a text field into a variable. All i want to do is have a text field, be able to type some text and then save this text into a variable. Could anyone tell me how to do this? Or point me in the right direction. Thanks!

Figured it out! 

Can I gently point out that it is frowned upon to answer your own forum post with “Figured it out!” or “Never mind,  I fixed it” without specifying HOW you fixed it for other people (and that applies to all forums, not just Corona).

It prevents the same questions being asked again and again, and is just common courtesy to help people who may have the same problem in future.

I’ll answer the question this time.

First create a listener that will handle events from your text input field:

myTextString = "" -- TextField Listener local function fieldHandler( event ) if ( "began" == event.phase ) then elseif ( "editing" == event.phase ) then myTextString = event.target.text elseif ( "ended" == event.phase ) then myTextString = event.target.text native.setKeyboardFocus( nil ) end end

The create your textfield and add the listener:

inputTextField = native.newTextField(0, 0, 200, 50) inputTextField:addEventListener("userInput", fieldHandler) --I create my text when the user needs it, and automatically set focus to it. --Using a delay makes this work more reliably. timer.performWithDelay(50, function()native.setKeyboardFocus( inputTextField )end, 1)

Now when the user types, the “myTextString” variable will be updated during the editing and  ended phases. Obviously you can change that listener to work as you need it to, but this is the general idea. I would think that you could also access “inputTextField.text” at any time as well, but I’ve always used the listener function as it gives me a bit more control over exactly when I want to access it.

Figured it out! 

Can I gently point out that it is frowned upon to answer your own forum post with “Figured it out!” or “Never mind,  I fixed it” without specifying HOW you fixed it for other people (and that applies to all forums, not just Corona).

It prevents the same questions being asked again and again, and is just common courtesy to help people who may have the same problem in future.

I’ll answer the question this time.

First create a listener that will handle events from your text input field:

myTextString = "" -- TextField Listener local function fieldHandler( event ) if ( "began" == event.phase ) then elseif ( "editing" == event.phase ) then myTextString = event.target.text elseif ( "ended" == event.phase ) then myTextString = event.target.text native.setKeyboardFocus( nil ) end end

The create your textfield and add the listener:

inputTextField = native.newTextField(0, 0, 200, 50) inputTextField:addEventListener("userInput", fieldHandler) --I create my text when the user needs it, and automatically set focus to it. --Using a delay makes this work more reliably. timer.performWithDelay(50, function()native.setKeyboardFocus( inputTextField )end, 1)

Now when the user types, the “myTextString” variable will be updated during the editing and  ended phases. Obviously you can change that listener to work as you need it to, but this is the general idea. I would think that you could also access “inputTextField.text” at any time as well, but I’ve always used the listener function as it gives me a bit more control over exactly when I want to access it.