Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to make button that alert reply id of user in javascript?

  • @chandra08

    Participant

    Hello, I dont know if I’m asking in the right place.

    But, I want to ask about code that has a connection with BBpress.

    I want to make a button in javascript that alert reply id of the user.

    This is my code:

    function engagement_post($reply_id = 0){
    
        $get_reply_id = bbp_get_reply_id($reply_id);
        $get_author_id= bbp_get_reply_author_id( $get_reply_id );
        echo $get_reply_id;
    
        ?>
        <style>
    
        .buttons{
                    background-color: #E8E8E8;
                    border-radius: 12px;
                }
    
        </style>
        
        <button class="buttons" onclick ="myFunction(this)" name="button1" type="button1" style="font-size:10px">BUTTON</button> 
    
        <script>
        const data =[
    
            {id: '<?php echo $get_reply_id ?>'}
        ];
        
        function myFunction(){
            var id = $(data).attr("id");
            alert('Button Clicked!, Reply ID:'+id);
    
        }
    
        </script>
    
        <?php
    
    }add_action('bbp_theme_after_reply_content', 'engagement_post');

    I’m already tried, but not find the answer. The code seems like only alert the first topic id. I mean, after topic id, the reply still alert same id. Example: Topic ID: 474, and then the other user reply and have reply id: 475, the javascript still alert 474.

    The purpose of this code, I want to make like and dislike button. So I need to make every button know what kind of reply id is it.

    All answer is very appreciated. Thank You Very Much

  • You must be logged in to reply to this topic.
Skip to toolbar