JQuery “greying” out textfield in form

I have the following function, but it does not blur out when the radio button is selected to no. Any ideas why?

Form Element:

<td>
    Email: Yes? <input type="radio" name="emailquest" value="true" checked>
    No? <input type="radio" name="emailquest" value="false">
</td>
<td>
    <input type="text" name="email">
</td>

Script:

<script>
    $(document).ready(function(){
        $("#emailquest").blur(function(){
            if ($(this).val() != true)
                $("#email").attr("disabled","disabled");
            else
                $("#email").removeAttr("disabled");
        });
    });                     
</script>

Answers


As Pointy said, # is used for ID's, not names

$("input[name='emailquest']").change(function(){
    if (this.value != "true") { // <----I would probably change this to look for this.checked
        $("input[name='email']").prop("disabled", true);
    } else {
        $("input[name='email']").prop("disabled", false);
    }
});

Live demo: http://jsfiddle.net/E3zDB/

Shortened version using a ternary operator:

$("input[name='emailquest']").change(function(){
    var input = $("input[name='email']");
    this.value != "true" ? input.prop("disabled", true) : input.prop("disabled", false);
});

Need Your Help

Pushing object with observable properties in observable array still track object's propteries.

javascript knockout.js knockout-2.0

I have an object addItem with several observable properties. Once the properties are populated I push this into an observable array allItems that tracks all the object created during a session.

Celery slowing down django

django celery supervisord kombu

I have a django 1.3 site using SQLite. It works well.