6 Replies Latest reply on Jul 18, 2008 10:27 AM by Rothrock

    Dynamic Field Left Empty (k)

    Level 7
      I have a loan calculator that is working. As long as the field has
      something entered. If the field is left blank, it doesn't work because
      the variable assigned to the field is empty.

      How can I write an IF statement for this? I've tried:
      if (VariableStaffordLoanText.text == "") {
      _global.VariableStaffordLoanVar = 0;
      }

      doesn't work.

      Also tried:

      if (VariableStaffordLoanText.text == null) {
      _global.VariableStaffordLoanVar = 0;
      }

      Thoughts?

      -Kirk
        • 1. Re: Dynamic Field Left Empty (k)
          Level 7
          Also tried ==undefined

          No dice.

          Is there a way to set the default value of a dynamic text field?

          -kirk


          W. Kirk Lutz wrote:
          > I have a loan calculator that is working. As long as the field has
          > something entered. If the field is left blank, it doesn't work because
          > the variable assigned to the field is empty.
          >
          > How can I write an IF statement for this? I've tried:
          > if (VariableStaffordLoanText.text == "") {
          > _global.VariableStaffordLoanVar = 0;
          > }
          >
          > doesn't work.
          >
          > Also tried:
          >
          > if (VariableStaffordLoanText.text == null) {
          > _global.VariableStaffordLoanVar = 0;
          > }
          >
          > Thoughts?
          >
          > -Kirk
          • 2. Re: Dynamic Field Left Empty (k)
            Rothrock Level 5
            Right before your conditional add this:

            trace("The field value is: ["+VariableStaffordLoanText.text +"]")

            Cut and paste the trace.
            • 3. Re: Dynamic Field Left Empty (k)
              Level 7
              I don't get it. How would a trace fix the problem? It traces and only shows:

              The field value is: []

              In the Output window

              -Kirk


              Rothrock wrote:
              > Right before your conditional add this:
              >
              > trace("The field value is: ["+VariableStaffordLoanText.text +"]")
              >
              > Cut and paste the trace.
              • 4. Re: Dynamic Field Left Empty (k)
                Rothrock Level 5
                Just a test to see if there is an invisible character in the text field. If I make a dynamic text field html enabled, the default seems to be a return.

                Over all there must be something else going on with your textfield. Because if I use the following code it tells me the default input is "nothing".

                trace("Value is: ["+theField.text+"]")
                if(theField.text==""){
                trace("It is nothing");
                }
                if(theField.text==null){
                trace("It is null");
                }
                if(theField.text==undefined){
                trace("it is undefined");
                }

                Anyways, the following line should help, maybe?

                var value:Number= isNaN(parseInt(theField.text)) ? 0 : parseInt(theField.text);
                • 5. Re: Dynamic Field Left Empty (k)
                  Level 7
                  I put this in:
                  trace("VariableStaffordLoanText.text 01"+VariableStaffordLoanText.text);
                  var value:Number = isNaN(parseInt(VariableStaffordLoanText.text)) ? 0 :
                  parseInt(VariableStaffordLoanText.text);
                  trace("VariableStaffordLoanText.text 02"+VariableStaffordLoanText.text);


                  It yielded nothing before and after your code.

                  I'm just going to leave it as defining the text field with 0.

                  Thanks for the help.

                  -Kirk



                  Rothrock wrote:
                  > Just a test to see if there is an invisible character in the text field. If I
                  > make a dynamic text field html enabled, the default seems to be a return.
                  >
                  > Over all there must be something else going on with your textfield. Because if
                  > I use the following code it tells me the default input is "nothing".
                  >
                  > trace("Value is: ["+theField.text+"]")
                  > if(theField.text==""){
                  > trace("It is nothing");
                  > }
                  > if(theField.text==null){
                  > trace("It is null");
                  > }
                  > if(theField.text==undefined){
                  > trace("it is undefined");
                  > }
                  >
                  > Anyways, the following line should help, maybe?
                  >
                  > var value:Number= isNaN(parseInt(theField.text)) ? 0 : parseInt(theField.text);
                  >
                  • 6. Re: Dynamic Field Left Empty (k)
                    Rothrock Level 5
                    Well the code I gave won't change the value of the text field (although you could modify to do that. But the variable called value should be zero if the value in the text field is not a number and the number if it is.

                    I still think there must be something tricky going on here. Good luck with your project sorry we couldn't get this sorted easily.