1

I created a table with radio button using ajax request. I want to get value from radio button by click event. But jquery event doesn't work on radio button. my created table by ajax below

enter image description here

I have called this ajax result by bellow code

<code>
<script type="text/javascript">
    $(document).ready(function(){
        $(".todayTask").click(function(){
            var employee = '<?php echo trim($userID);?>';
            $.ajax({
                url: "ajax_call.php",
                type:"POST",
                data:{userID:employee},
                success: function(result){
                    $('#taskList').html(result);
            }});
        });
    });
</script>
</code>

Now I want to get value from radio button which stay in ajax result... by below code but does not work...

<code>
<script type="text/javascript">
    $(document).ready(function(){
        $("#s").click(function(){
            var status_val = $(this).val();
            alert(status_val);
        });
    });
</script>
</code>
Sachin I
  • 1,500
  • 3
  • 10
  • 29
Salman Quader
  • 195
  • 2
  • 13
  • Post text, not pictures of text. – T.J. Crowder May 16 '16 at 05:48
  • 1. IDs need to be unique. Change the `id="s"` to `data-type="start", data-type="pause"` and so on. 2. defer the click to the nearest container: `$('#taskList').on("click","input[name='s']",function() { console.log($(this).data("type")) });` – mplungjan May 16 '16 at 05:56

2 Answers2

1

Since your radio buttons are loaded via jquery, you need to use on event:

$(document).ready(function(){
        $('#taskList').on("click","#s", function(){
            var status_val = $(this).val();
            alert(status_val);
        });
    });

You need to also use a class ".s" instead of an ID "#s", because an ID needs to be unique, here is an example:

$('#taskList').on("click",".s", function(){
Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52
0

Bind your click event using on:

$("table").on("click","#s" ,function(){
    var status_val = $(this).val();
    alert(status_val);
});

Note: ID must me unique. So, either use classes or make sure you have unique id

Sandeep Nayak
  • 4,649
  • 1
  • 22
  • 33