Skip to main content
Known Participant
September 28, 2012
Question

Detecting Text Input

  • September 28, 2012
  • 1 reply
  • 558 views

How do i detect if there is some text entry in the input text field.

---------------------------------------------------------------------- -------------

this.tf1_txt.text = "";

this.tf1_txt.onSetFocus = function() {

tf1_txt.text=(tf1_txt.text == "")?  "" : tf1_txt.text ;

}

this.tf1_txt.onChanged=function(){

if(this.tf1_txt.text==""){

this.submit_btn.enabled=false;

}else {

          this.submit_btn.enabled=true;

}

}

this.submit_btn.onRelease = function  () {

gotoAndStop("complete");

}

---------------------------------------------------------------------- -----------------

If I am using If . . else if. How would the above code mentioned in red color change ?

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
September 28, 2012

If that is a multiline textfield then you will find it comes with some extra baggage in the form of a carriage return.  So even before any text is entered into it there is that living there.  It can be deleted if you were to use the delete key while the textfield looked empty.  So since the textfield could have 0 or 1 characters and be empty, you might want to change your test to be <2 insteasd == ""

You should avoid unnecessary use of "this"   If the code is in the same timeline as the object it is targeting, there is no need for it and it can cause problems.  If your textfield happens to be a single line textfield, using this could cause a problem.

You should learn to use the trace() function to troubleshoot your coding.  It allows you to see what values are being processed and enables you to question why some are not what you expect them to be.