Expand my Community achievements bar.

Dynamically change text field type

Avatar

Former Community Member

Hello all

I have a form which displays a decimal field. However when certain conditions are met, I need to change its type to Text, so the user can enter any alphanumeric character.

How do I achieve that with Javascript code? Is it even possible?

3 Replies

Avatar

Former Community Member

You will not be able to change the field type dynamically. You will have to set the field type as text and then use javascript to restrict the input to the field.

Paul

Avatar

Former Community Member

If you place a Text field and a Decimal Field in the same location, set the Text field's presence to Hidden and then add script to switch it to Visible while switching the Presence for the Decimal field to Hidden that might mimic what you're looking for.

Avatar

Level 1

Actually, you can dynamically change a textfield.type. AS2.0

You need two elements.

txt.type = "input";

txt.selectable = true;

However, if you have the textfield in a btn you will need to

delete the onRelease function before you can make the tf function correctly.

btn.onRelease = function()

{

delete this.onRelease;


this.txt.type = "input";

this.txt.selectable = true;

}