Checking value

4 posts, 1 answers
  1. Karl Ranville
    Karl Ranville avatar
    28 posts
    Member since:
    Mar 2013

    Posted 26 Mar 2013 Link to this post

    Hi,

    I got a RadTextBox and after user enter some value and move to the next textbox, I want to check if the value is greater than 18. And if the condition fails, display an alert and clear text.

    Thanks,
    Karl.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Mar 2013 Link to this post

    Hi Karl,

    Please have a look into the following code.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
        <ClientEvents OnBlur="OnBlur" />
    </telerik:RadTextBox>

    JavaScript:
    <script type="text/javascript">
        function OnBlur(sender, args) {
            var value = parseInt(sender.get_value());
            if (value < 18) {
                alert("Invalid Value");
                sender.clear();
            }
        }
    </script>

    I have one suggestion, you may better use the RadNumericTextBox because if you are entering some alphabets or invalid characters, then the JavaScript wont work.

    Thanks,
    Princy.
  3. Karl Ranville
    Karl Ranville avatar
    28 posts
    Member since:
    Mar 2013

    Posted 29 Mar 2013 Link to this post

    Thanks princy. As you told, the JS does not work for invalid entries. I am thinking of using RadNumericTextbox.
  4. moegal
    moegal avatar
    278 posts
    Member since:
    Jul 2007

    Posted 31 Mar 2013 Link to this post

    you could first test value for isNaN
Back to Top