且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅在单击单选按钮1时启用文本框

更新时间:1970-01-01 07:55:06

我想,您应该为此使用一些常规处理程序: http://jsfiddle.net/maximglad​​kov/MvLXL/

  $(function(){
window.invalidate_input = function(){
if($('input [name = XIAlmnus]:checked ').val()==Yes)
$('#XIyop')。removeAttr('disabled');
else
$('#XIyop')。attr 'disabled','disabled');
};

$(input [name = XIAlmnus])。change(invalidate_input);

invalidate_input( );
});


I have 2 radio button ie yes and no. When I select yes the text box as to get enabled. When i click no the text box as to be disabled. How to enable the text box when I click on Yes. Here is the code. Please tel me how to enable and disable it using javascript.

<script type="text/javascript">
$(function() {

    $("#XISubmit").click(function(){

        var XIyop= document.forms["XIForm"]["XIyop"].value;
        var XIForm = $('form[name=XIForm]');
        var XIAlmnus = XIForm.find('input[name=XIAlmnus]:checked').val();

        if (XIAlmnus == null || XIAlmnus == "") 
        {
            alert("Please select  Parent is an Alumnus (old Boy) of this school");
            return false;
        }
        document.getElementById("XIForm").submit();
    });
</script>        

<!-- html code-->
<html>
...
<label>Parent is an Alumnus (old Boy) of this school </label> &nbsp&nbsp
<input type='radio' name='XIAlmnus' value='Yes' id="XIyes"/>Yes
<input type='radio' name='XIAlmnus' value='No' id="XIno"/>No</td>

<label>If Yes, Year of passing </label> &nbsp&nbsp
<input type="textbox" name="XIyop" id="XIyop" >
...
</html>

I think, you should use some general handler for this: http://jsfiddle.net/maximgladkov/MvLXL/

$(function() {
    window.invalidate_input = function() {
        if ($('input[name=XIAlmnus]:checked').val() == "Yes")
            $('#XIyop').removeAttr('disabled');
        else
            $('#XIyop').attr('disabled', 'disabled');
    };

    $("input[name=XIAlmnus]").change(invalidate_input);

    invalidate_input();
});