Link to home
Start Free TrialLog in
Avatar of RadhikaVyas
RadhikaVyasFlag for India

asked on

Textbox validation in javascript in asp.net

HI
I want to validate textbox using javascript as per some radio button check property..I have two radiobuttons r1 and r2...Two sets of textboxes gets activated as per radio button checked......i want to validate that textboxes in javascript....Can anyone help me out immediately........
Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

Just implemented sample code to validate length of textboxes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function chkradio1() {
            var radios = document.getElementsByName('preferred_color');
            if (radios[0].checked == true) {
                document.getElementById("Text2").disabled = true;
                document.getElementById("Text1").disabled = false;
            }
            else {
                document.getElementById("Text1").disabled = true;
                document.getElementById("Text2").disabled = false;
            }
        }
        function validate(text) {
            if (text.length > 10) {
                alert("Length more than 10 characters");
            }
        }
    </script>
</head>
<body>
    <p>
        <b>validations:</b></p>
    <input type="radio" name="preferred_color" value="one" onclick="chkradio1();" />
    one<br />
    <input type="radio" name="preferred_color" value="two" onclick="chkradio1();" />
    two<br />
    <input id="Text1" type="text" disabled="disabled" onkeydown="validate(this.value);" />
    <input id="Text2" type="text" disabled="disabled" onchange="validate(this.value);" />
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of experts1
experts1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial