Q: Uploading Information to a database with a disabled textbox I have  form that has 2 radio buttons(Yes and No) and a text box. If the user clicks Yes it enables the text box you can input information and it is uploaded to the database including the value from the radio buttons. If you click no it disables the text box and suppose to upload the value of the radio box only to  the database. But I am not getting that.
<input type="radio" name="TermLease" value="No" onclick="TermLeaseMonths.disabled=true">No
<input type="radio" name="TermLease" value="Yes"  onclick="TermLeaseMonths.disabled=false">Yes | 
How many months:<input type="hidden" name="TermLeaseMonths"  value="0" />
<input type="text" name="TermLeaseMonths" id="TermLeaseMonths" size="1" disabled="true">

I have a hidden input type that uploads the value. But when I click yes it does not disable the text box. Not sure where I am going wrong.

A: You forgot give id for the text field. Try this
<input type="radio" name="TermLease" value="No" onclick="TermLeaseMonths.disabled=true">No
<input type="radio" name="TermLease" value="Yes"  onclick="TermLeaseMonths.disabled=false">Yes | 
How many months:<input type="hidden" name="TermLeaseMonths"  value="0" />
<input type="text" name="TermLeaseMonths" id="TermLeaseMonths" size="1" disabled="true">


A: Try this on click of radio button we can do by this way 
$('#radio').click(function () {
    if (("#radio").val() == "") {
        $('class_name_oftextBox').attr("disabled", true);
    } else {
        $('class_name_oftextBox').removeAttr("disabled");
    }
});

Or you can do this as 
$('#enable').click(function () {
    $('#textBox').removeAttr("disabled")
});
$('#disable').click(function () {
    $('#textBox').attr("disabled", "disabled");
});


A: Demo jsFiddle
HTML
<form>
    <span style="float: left;">
        <label><input type="radio" name="TermLease" value="No" onclick="ShowHideTextbox('leaseMonths', false)" />No</label>
        <label><input type="radio" name="TermLease" value="Yes"  onclick="ShowHideTextbox('leaseMonths', true)"/>Yes</label>
    </span>

    <span id="leaseMonths" style="display: none; float: left;">
        <span> | </span>  <span>How many months: </span>
        <input type="text" name="TermLeaseMonths" id="TermLeaseMonths" size="1" />
    </span>
</form>

JS
var previousNumberOfMonths = "0";

function ShowHideTextbox(elementId, show) {
    var link = document.getElementById(elementId);
    var textbox = document.getElementById("TermLeaseMonths");
    if (show){    
        textbox.value = previousNumberOfMonths;

        link.style.display = 'block';
    }
    else {
        link.style.display = 'none';
        previousNumberOfMonths = textbox.value;

        document.getElementById("TermLeaseMonths").value = "0";
    }
}

