Insert cursor on click of a button

Insert cursor on click of a button

Hello,
The code below puts the Reply form and Topic form for BBPress in a slide out. I would like the cursor to be automatically inserted on these conditions.

  • User clicks Create Topic button, slide out opens, cursor is inserted in the Title field.
  • User clicks Reply, slide out opens, cursor is inserted in to Reply field/textarea.

Can you please help me modify my code so it does this?

Code in functions.php of my WordPress theme:

  1. /*Add reply form slide out on BBPress*/
    function show_form_on_click() {
        $classes = get_body_class();
    
        if ( is_user_logged_in() && !bbp_is_topic_closed() ) {
    
            if (in_array('single-forum',$classes)) { ?>
                <script type="text/javascript">
                    jQuery( document ).ready(function() {
        jQuery( '<a class="custom-newtopic-button">Create Topic</a>' ).insertBefore( '#new-topic-0' );
                        jQuery('.custom-newtopic-button').click(function(){
                            jQuery('.custom-newtopic-button').hide();
                        });
                        jQuery('.custom-newtopic-button').click(function(){
                            jQuery('.bbp-topic-form').show();
                        });
                    });
                </script>
            <?php } elseif(in_array('single-topic',$classes)) { ?>
                <script type="text/javascript">
                    jQuery( document ).ready(function() {
                        jQuery( '<a class="custom-reply-button">Reply</a>' ).insertAfter( '.bbp-pagination' );
                        jQuery('.custom-reply-button, .d4p-bbt-quote-link').click(function(){
                            jQuery('.custom-reply-button').hide();
                        });
                        jQuery('.custom-reply-button, .d4p-bbt-quote-link').click(function(){
                            jQuery('.bbp-reply-form').show();
                        });
                    });
                </script>
            <?php }
        }
    }
    add_action( 'wp_footer', 'show_form_on_click' );
Thanks.

Alex S
Website administration is my dream job!
http://yourtechadvisors.com