views:

164

answers:

2

I have a radiobutton set called 'daypattern'. Clicking on it should enable the checked member's formfield siblings and disable the formfield siblings (if any) of other members. I am trying to compare the value of the checked field with the value of the current radio button but the checked field value is returning an integer rather than the expected string from the radio button's value attribute.

Where is it getting this number? How can I fix it and is there a better approach?

Thanks

problem function:

 $.fn.setActiveState=function(){
  var c=$(this+':checked').val();//c=3 instead of 'everyday' OR 'everywday'. WHY?
  this.each(function(){
    alert(c + ' and '+ $(this).val());//3 and 'everyday' OR 'everywday'
    if($(this).val()== c){
   $(this).siblings(':input').removeAttr("disabled"); 
    }else{
   $(this).siblings(':input').attr('disabled',true); 
    }
  });
 }

HTML

<label>
  <input type='radio' name='daypattern' value='everyday' checked='checked'/>Every 
  <input type='text'class='numtext' name='day_increment' value='1'/> day(s)
</label>

<label>
  <input type='radio' name='daypattern' value='everywday'/>Every weekday
</label>

call problem function in $(document).ready:

$("input[name='daypattern']").setActiveState();
+4  A: 

Try switching to:

$(this).filter(':checked').val();
cballou
Probably better than my suggestion, didn't quite understand the call chain at first..
gnarf
That does it! Thanks. I just wish I knew what the other expression `$(this +':checked').val()` was accessing? Perhaps it ignores the 'this' and returns the first value of the first member of `:checked`?
dnagirl
Istr "this" is an object (an array?) rather than just a string identifying the element, so `this+':checked'` evaluates to .... goodness only knows.
araqnid
A: 

Try

var c=$(':checked', this).val();//
gnarf