Jump to content

Automatically fill one input box with text from another input box


anutt217
 Share

Go to solution Solved by Musashi,

Recommended Posts

Hello, I'm new to using Autoit and I was wondering if there is a way to have text that is entered in one box show up in another box. Since everyone's username and email start the same (first.last name) at my work, I want it so all you have to type is the username and it will autofill in the email address. Any help would be greatly appriciated.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1", 372, 218, 192, 124)
GUISetBkColor(0x008080)
$Username = GUICtrlCreateInput("Username", 35, 56, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Useremail = GUICtrlCreateInput("email", 35, 84, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_LOWERCASE,$ES_READONLY))
$Password = GUICtrlCreateInput("password", 35, 112, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Computer = GUICtrlCreateLabel("Computer Setup", 80, 8, 213, 34)
GUICtrlSetFont(-1, 18, 400, 0, "Showcard Gothic")
$Exit = GUICtrlCreateButton("Exit", 216, 168, 123, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        case $Useremail
            Send($Username & "@email.com")

        Case $Exit
            Exit

    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Solution
44 minutes ago, anutt217 said:

Since everyone's username and email start the same (first.last name) at my work, I want it so all you have to type is the username and it will autofill in the email address.

Try this :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1", 372, 218, 192, 124)
GUISetBkColor(0x008080)
$idUsername  = GUICtrlCreateInput("Username", 35, 56, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$idUseremail = GUICtrlCreateInput("email", 35, 84, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_LOWERCASE,$ES_READONLY))
$idPassword  = GUICtrlCreateInput("password", 35, 112, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Computer  = GUICtrlCreateLabel("Computer Setup", 80, 8, 213, 34)
GUICtrlSetFont(-1, 18, 400, 0, "Showcard Gothic")
$Exit = GUICtrlCreateButton("Exit", 216, 168, 123, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idUsername
            GUICtrlSetData($idUseremail, GUICtrlRead($idUsername) & "@email.com")
        Case $Exit
            Exit
    EndSwitch
WEnd

Edit : @anutt217

Explanation :

GUICtrlCreateInput returns a controlID on success, not the data (in this case e.g. not the 'username') itself. To read or set the data you have to use GUICtrlRead or GUICtrlSetData.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Here is modification which reacts on each keypress:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

#Region ### START Koda GUI section ###
$Form1_1 = GUICreate("Form1", 372, 218, 192, 124)
GUISetBkColor(0x008080)
$idUsername  = GUICtrlCreateInput("Username", 35, 56, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$idUseremail = GUICtrlCreateInput("email", 35, 84, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_LOWERCASE,$ES_READONLY))
$idPassword  = GUICtrlCreateInput("password", 35, 112, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
$Computer  = GUICtrlCreateLabel("Computer Setup", 80, 8, 213, 34)
GUICtrlSetFont(-1, 18, 400, 0, "Showcard Gothic")
$Exit = GUICtrlCreateButton("Exit", 216, 168, 123, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Exit
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWinHandle, $iMsg, $wParam, $lParam)
    If _WinAPI_LoWord($wParam) = $idUsername And _WinAPI_HiWord($wParam) = $EN_CHANGE Then
        GUICtrlSetData($idUseremail, GUICtrlRead($idUsername) & "@email.com")
    EndIf
EndFunc

 

Link to comment
Share on other sites

36 minutes ago, Zedna said:

Here is modification which reacts on each keypress:

This is certainly the more elegant solution. I had it in mind as well (this question didn't arise for the first time), but wanted to stay as close to the OP's original code as possible so he could follow it ;).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...