2 Replies Latest reply on Jul 28, 2010 7:34 AM by rtalton

    TextInput change text on click

    djh88ukwb Level 1

      Hello all.

       

      I have a text input that has the text "Name".  What i want to do, is when this is clicked it gets rid of this text.  I can do it this way

      <s:TextInput x="10" y="291" width="265" textDecoration="none" text="Name" id="txt_name" click="txt_name.text=''" fontStyle="italic"/>

       

      Simply changing the value of text to "" on the click attribute.

       

      However this causes problems because if you click it once it gets rid of "Name" and then you type in something, if you clicked it again it would get rid of what you typed in.

       

      So i though about this simple function

       

                  protected function commentnametext():void
                  {
                      if (txt_name2.text == 'Name')
                      {
                          txt_name2.text == '';
                      }
                      else
                      { }
                  }

      <s:TextInput x="10" y="321" width="265" textDecoration="none" text="Name" id="txt_name2" click="commentnametext()" fontStyle="italic"/>

       

      However when i click the textarea it dosent seem to run the function, the text dosent change.  Any ideas why its not working?

        • 1. Re: TextInput change text on click
          VRPDeveloper Level 3

          Your function is wrong

           

          protected function commentnametext():void
                      {
                          if (txt_name2.text == 'Name')
                          {
                            txt_name2.text == '';  --- you have to write here txt_name2.text=''; instead of 2 == write only 1 =
                          }
                          else
                          { }
                      }

           

          If this post answers your question or helps, please kindly mark it as such.

          • 2. Re: TextInput change text on click
            rtalton Level 4

            Also, you might want to consider people with disabilities who don't use a mouse. Try using the focusIn event to accomplish what you are doing.

            You could then use the focusOut event to restore any default text if the user made no changes.

            1 person found this helpful