What's wrong in my validation of SelectBox

  1. #1

    What's wrong in my validation of SelectBox

    I have written the following script to check whether selected index of Select Box is -1 or not but this is not working for me can any one help me.

    <script type="text/javascript">
            var onBeforeSubmit = function (select) {
                if (select.value==-1) {
                    Ext.Msg.alert("Error", "Select an item.");
                    return false;
                }
            };
        </script>
    This is my button design

      <ext:Button ID="Button1" runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="Select" Before="return onBeforeSubmit(#{SelectBox1})" />
                </DirectEvents>
            </ext:Button>
  2. #2
    Hi,

    Well, the SelectBox value doesn't consist an index of a selected item.

    I can suggest the getValue method, it returns null if there is no selected item.

    Example
    #{SelectBox1}.getValue() === null
  3. #3
    You mean like this

     <script type="text/javascript">
            var onBeforeSubmit = function () {
                if (#{SelectBox1}.getValue() === null) {
                    Ext.Msg.alert("Error", "Select an item.");
                    return false;
                }
            };
        </script>
    But still I am unable to display the alert
  4. #4
    Did you wrap that <script> in <ext:XScript> control? To get #{} syntax working.
  5. #5
    Can you give me the code please I am not that much familiar with these tools and scripts
  6. #6
    Well, your initial code should work, just replace
    if (select.value==-1) {
    with
    if (select.getValue() === null) {
  7. #7
    Thanks Danill...

Similar Threads

  1. Cannot get SelectBox value
    By Irmak in forum 2.x Help
    Replies: 4
    Last Post: Jun 07, 2012, 5:49 PM
  2. Client Side Validation and Validation Status
    By speddi in forum 1.x Help
    Replies: 8
    Last Post: Nov 03, 2011, 11:24 AM
  3. Replies: 4
    Last Post: Oct 24, 2011, 3:34 AM
  4. Replies: 3
    Last Post: Jul 11, 2011, 9:43 AM
  5. [CLOSED] Validation formpanel. What's wrong ?
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Sep 07, 2010, 2:22 PM

Posting Permissions