Avatar of RadhikaVyas
Flag for India asked on

Textbox validation in javascript in asp.net

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 undefined
Last Comment

8/22/2022 - Mon
Anuradha Goli

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">
    <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");
    <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);" />

Open in new window


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes