script not working in Ajax returned value

前端 未结 3 1573
孤独总比滥情好
孤独总比滥情好 2021-01-07 09:11

I am displaying item id and title.there is also a link \"show items of this member\".while clicking on it it will display the items of that user.I am using ajax for this.The

相关标签:
3条回答
  • 2021-01-07 09:40

    You should probably change click in script to on

    0 讨论(0)
  • 2021-01-07 09:59

    Use this script

    <script type="text/javascript">
    var array = []; 
        $('#item').live('click', function() {
    if ($(this).attr('checked')) { 
                // Add the new element if checked: 
                array.push($(this).attr('value')); 
                document.getElementById('hidden_field').value=array.join(',');
            } 
            else { 
                // Remove the element if unchecked: 
                for (var i = 0; i < array.length; i++) { 
                    if (array[i] == $(this).attr('value')) { 
                        array.splice(i, 1); 
                    } 
                } 
            } 
    
    
    });
    
    </script>
    
    0 讨论(0)
  • 2021-01-07 10:04

    You are not calling onclick function in your ajax generated code. In getdetails.php Change

    <input type="checkbox" name="item" id="item" value="'.$row[item_id].'">
    

    to

    <input type="checkbox" onclick="javascript:call_check()" name="item" id="item" value="'.$row[item_id].'">
    

    Also id attribute of any html tag should be unique. This may not create any problem, but definitely not a good practice.

    0 讨论(0)
提交回复
热议问题