This is a migrated thread and some comments may be shown as answers.

Checking value

3 Answers 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Karl Ranville
Top achievements
Rank 1
Karl Ranville asked on 27 Mar 2013, 03:00 AM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Mar 2013, 04:59 AM
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.
0
Karl Ranville
Top achievements
Rank 1
answered on 29 Mar 2013, 01:34 PM
Thanks princy. As you told, the JS does not work for invalid entries. I am thinking of using RadNumericTextbox.
0
moegal
Top achievements
Rank 1
answered on 31 Mar 2013, 10:41 AM
you could first test value for isNaN
Tags
General Discussions
Asked by
Karl Ranville
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Karl Ranville
Top achievements
Rank 1
moegal
Top achievements
Rank 1
Share this question
or