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

MySQL Query add limit in SubQuery

mysql subquery

Here is my table test with values:

NotifyDataSetChanged from fragment container

android android-fragments android-listfragment

I have an app with an Activity that hosts a ListFragment, an EditText, and a Button. When the user presses the Button, I want to add the text in the EditText to the ListFragment. I know to do this, I

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.