Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using Checkbox to enable/disable input text.

New Here ,
May 21, 2008 May 21, 2008
Can anyone help me with the Actionscript for having a checkbox when CHECKED it allows certain input text fields to be enabled, and when UNCHECKED they are disabled?

I am making a Shipping/Billing application and want it to have a checkbox so if they information is the same as the previous they can check the box and disable the fields.
TOPICS
ActionScript
2.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 21, 2008 May 21, 2008
Sorry, I wasn't thinking, Try:

function clickHandler(event:MouseEvent):void {
inputtext.selectable = !event.target.selected;
}

Though it should have been selectable until you checked the checkbox since nothing set it false ahead of that.
Translate
Community Expert ,
May 21, 2008 May 21, 2008
assign your textfield's type property to be TextFieldType.DYNAMIC and TextFieldType.INPUT when you want to disable and enable it, resp.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2008 May 21, 2008
Unless this has changed for textfields between AS2 and AS3, you can also set the selectable property as true/false to enable/disable access.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2008 May 21, 2008
selectable won't work. you can still enter text in a textfield whose text you cannot select.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2008 May 21, 2008
Maybe I wasn't clear on what I am looking for, but I am creating a Shipping / Billing input form, and if the user's information is the same in the shipping as it is billing, I want them to check a box to disable the boxes.

I think it will be something like the attached code, however this code only allows the input text boxes to be ENABLED when the checkbox is checked, not DISABLED.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2008 May 21, 2008
Unless I've missed something somewhere (which isn't impossible), TextFields do not have an 'enabled' property. They have a 'selectable' property that you can set as true or false. Setting the selectable property false for an input text field effectively disables it.

If you can't select it, you can't enter anything into it. You can probably have actionscript do it, but then you can have that done for dynamic fields as well.

So your code should be:

inputtext.selectable = true;

function clickHandler(event:MouseEvent):void {
inputtext.selectable = event.target.selected;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2008 May 21, 2008
I appreciate the responses but I am still not getting the outcome I need. What your code does is makes the text field not selectable until the checkbox is selected, but I need the text field to be selectable ASLONG as the checkbox ISNT selected, and once the function is activated (eg. checking the box), the text field ISNT selectable until the box is unselected. Can anyone help with that?

Also I was considering using the TextInput Component since it does have a .enabled = true; syntax.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2008 May 21, 2008
Sorry, I wasn't thinking, Try:

function clickHandler(event:MouseEvent):void {
inputtext.selectable = !event.target.selected;
}

Though it should have been selectable until you checked the checkbox since nothing set it false ahead of that.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2008 May 21, 2008
Wow that worked! Thank you! Can't believe my solution was just one tiny !.

Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 21, 2008 May 21, 2008
You're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2008 May 21, 2008
again, assigning an input textfield's selectable property to false will NOT prevent text from being entered. it just prevents a user from selecting the text (that they may have entered).

re-read my above message.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2008 May 22, 2008
No need to reread, just a need to retest... and you're right--learning new stuff every day! I always assumed that no cursor meant no entry possible, so I never actually tried typing anything. Luckily, it's nothing I have to alert any clients about and change.

In that case, the following will work instead...

function clickHandler(event:MouseEvent):void {
inputtext.mouseEnabled = !event.target.selected;
}

If there's a problem with this approach, I'll be happy to learn that too.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 22, 2008 May 22, 2008
Kglad is right. You can still enter.

So is it possiple to prevent this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2008 May 22, 2008
Since we posted within seconds of each other, you may have missed my alternative... If kGlad returns, then we'll hopefully see if his solution (changing it to a dynamic field) is the only safe solution for some reason.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 22, 2008 May 22, 2008
inputtext.mouseEnabled=false;

seems better solution. Thanks Ned.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2008 May 22, 2008
LATEST
if you think that's better, you should check if a user can tab into your textfield.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines