Skip to content Skip to sidebar Skip to footer

Javascript Query - Using And & Or With Radios, Checkboxes And Text Fields To Enable Form Elements

Please see the JSFiddle code I already have. My issue is that I require to use a radio check AND a text entry into a text field to enable other radios, checkboxes and text fields.

Solution 1:

you need to check the value of field1 when the cursor leaves it, try this:

  $("#field1").blur(function(){
   if($("#example_0").is(":checked")){
            if($("#field1").val()!==""){
                  $("#field3").removeAttr("disabled");
            }
        }
    });

http://jsfiddle.net/cEaeK/13/

Solution 2:

$(function(){
    $("#example_0, #example_1").change(function(){
        $("#field1, #field2").val("").attr("disabled",true);
        if($("#example_0").is(":checked")){
            $("#field1").removeAttr("disabled");
            $("#field1").focus();
        }
        elseif($("#example_1").is(":checked")){
            $("#field2").removeAttr("disabled");
            $("#field2").focus();   
             $("#field3").val('');
                              $("#field3").attr("disabled",true);
        }
    });

        $('#field1').focusout(function(){

            if($('#field1').val().length!=0)
                  $("#field3").removeAttr("disabled");
            else
            { $("#field3").val('');
                              $("#field3").attr("disabled",true);
            }

    });

});

Solution 3:

if(($("#example0").is(":checked") && $("#field0").val().length != 0) || ($("#example1").is(":checked") && $("#field1").val().length != 0)) {
    PASS!
}

Post a Comment for "Javascript Query - Using And & Or With Radios, Checkboxes And Text Fields To Enable Form Elements"