7 Replies Latest reply on May 31, 2011 11:57 AM by Gene Godsey

    onChange method

    Gene Godsey

      I know this is a JavaScript issue but I will go ahead and ask this anyway.

      I need a javascript function that will allow my textbox to enable the submit button in the form when the textbox becomes populated with text.

      Thanks in Advance.....

        • 1. Re: onChange method
          Dan Bracuk Level 5

          Your google search string is "javascript show hide"

          • 2. Re: onChange method
            Gene Godsey Level 1

            That is one idea BUT.............

             

            I need to have a method that the trigger an event via a textbox insertion/callback that will enable the submit button w/o having to use the onKeyUp method. The actual text field is hidden and the field needs to enable the disabled submit button.

             

            I.E.:

             

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

            <script language="javascript" type="text/javascript">
            function SetButtonStatus(sender, target) {
                if ( sender.value.length >= 1 )
                document.getElementById(target).disabled = false;
                 else
                document.getElementById(target).disabled = true;
            }
            <script>

             

            <asp:TextBox ID="txtText" runat="server" onkeyup="SetButtonStatus(this, 'btnButton')">asp:TextBox>
            <asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" />

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

            Sorry it's in Dot.Net but you get the idea.

            • 3. Re: onChange method
              Dan Bracuk Level 5

              You want to use the value of a hidden field to enable/disable the submit button?  Is there user input involved anywhere?

              • 4. Re: onChange method
                Gene Godsey Level 1

                There is a callback from another javascript method that is placing data into that field.

                There are no key strokes involved so the keyUp() method is not going to work.

                • 5. Re: onChange method
                  Dan Bracuk Level 5

                  Then perhaps the answer is to incorporate the enable/disable logic in that first javascript function.

                  • 6. Re: onChange method
                    gitobu

                    Dan,

                    I do not know whether you have an aswer yet but if your intention is

                    to stop a form from submitting when the text box is blank you may create a function that

                    ensures that the field is not blank, and have the function called on submit.

                     

                    <script type="text/javascript" language="javascript">

                    function ensureNotBlank (){

                    if (document.formname.fieldname.value == ""){
                      alert('Please enter a whaterver');
                      return false;

                    }

                     

                    }

                    </script>

                     

                    On your submit button:

                     

                    <input type submit" value="Send data" onClick="return ensureNotBlank()">

                     

                    If the textbox is blank you have the alert and the form is not submitted. If it is populated the form submits.

                     

                    Allan

                    1 person found this helpful
                    • 7. Re: onChange method
                      Gene Godsey Level 1

                      This is a possible solution but what I was really looking for was to keep the submit button disabled until the textbox was populated with content.