javascript - JQuery "greying" out textfield in form -


i have following function, not blur out when radio button selected no. 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> 

as pointy said, # used id's, not names

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

live demo: http://jsfiddle.net/e3zdb/

shortened version using ternary operator:

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

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -