Registering jquery radio button click event doesn't work -


i trying set hidden form field value of selected radio button. have following code:

    $(function () {         // set hidden form field selected timeslot         $('input[name=["timeslot"]').live("click", (function () {             var valu = $(this).val();             alert(valu);             $("#selectedslot").val(valu);         }));     }); 

all radio buttons have name "timeslot", , run function whenever 1 clicked. however, alert box shows blank when click 1 of radio buttons.

update: oops! didn't see double square brackets. fixed it:

        $('input[name="timeslot"]').live("click", (function () {             var valu = $(this).val();             alert(valu);             $("#selectedslot").val(valu);         })); 

and still having same problem. in fact, alert box not come more reason.

update 2: actually, in real code have other events registered in initiation block besides 1 -- if take out of them except radio button one, works!

for example, if have this:

    $(function () {         // set hidden form field selected interviewee         $('#interviewees').live("change", (function () {             var selected = $("#interviewees").val();             $("#selectedinterviewee").val(selected);         }));         // set hidden form field selected timeslot         $('input[name="timeslot"]').live("click", (function () {             var valu = $(this).val();             alert(valu);             $("#selectedslot").val(valu);         }));     }); 

then radio button click event not fire, though first 1 (a dropdown list) does. if have radio button 1 itself, does. ideas????

the input tags this:

<input id="slot_7:30-am" name="timeslot" type="radio" value="slot_7:30-am" /> 

i using ie 8 mostly, tried on firefox , same thing happened. doing wrong?

without seeing html, can't totally sure, i'm thinking problem selector you're using:

$('input[name=["timeslot"]') 

there @ least 2 problems might cause issues:

  1. the unclosed square-bracket, and
  2. the use of square brackets inside attribute selector. try using: $('input[name="timeslot"]') instead.


edited in response comments answer, below.

the following seems work:

$('input[name="timeslot"]').live('click', function() {     var valu = $(this).val();     alert(valu);     $("#selectedslot").val(valu); }); 

js fiddle demo.

i am, of course, using text input, rather hidden, since selector works on id should work regardless of input type.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -