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

asked on

Textbox validation in javascript in

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" "">
<html xmlns="">
    <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

Avatar of experts1

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