Ticket Q91639
Visible to All Users

Get the value of an aspxTextBox with Javascript

created 17 years ago

How would I extract the value of an aspxTextBox using javascript? Also, why is SO MUCH html generated, especially tables, for a simple textbox?

Answers approved by DevExpress Support

created 17 years ago (modified 12 years ago)

Hi Matt,
Please use the ASPxTextBox.GetValue client-side method for this purpose. Here is some sample code:
<script language=javascript>
    function getEditValue(){
        var value = ASPxTextBox1.GetValue();
        if(value)
            alert(value);
    }
</script>
Please try this solution and let us know your results.
As for your comments, this is how our ASPx editors are designed: all our editors are generated as HTML tables.
Thanks,
Vito

    Comments (3)

      I'm getting an undefined error. Here is my code:
      <script type="text/javascript">
      function clg_Find(category, text)
      {
          // Has any search text been provided?
          if (document.getElementById(text).GetValue == '')
          {
              alert('Please provide some text to search on.');
              document.getElementById(text).focus();
              return false;
          }

      var value = document.getElementById(text).GetValue;
          alert(document.getElementById(text)); ** This gives an [object] message **
          alert(value); ** This gives the undefined message **

      // Code to build the url goes here

      // Redirect the user
          location.href = url;
      }
      </script>
      The parameters are as follows:
      category is the ClientID of a AspxComboBox
      text is the ClientID of a AspxTextBox
      Any help would be appreciated! Thanks!

      DevExpress Support Team 17 years ago

        Hi Matt,
        It is not quite correct to use the document.getElementById method in this situation. Please use the aspxGetControlCollection().Get() method for this purpose. Here is a modified sample code:
        <script language=javascript>
            function getEditValue(editorID){
                var editor = aspxGetControlCollection().Get(editorID);
                if(editor){
                    var value = editor.GetValue();
                    if(value)
                        alert(value);
                }
            }
        </script>
        Thanks,
        Vito

          Thanks a lot…

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.