Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Insert cursor on click of a button

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240407
    Anonymous
    Inactive

    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:

    /*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.

    #240413
    Anonymous
    Inactive

    Hello,
    If you need to see it live,
    http://yourtechadvisors.com/forums/forum/other/
    &
    http://yourtechadvisors.com/forums/topic/testing-2/

    Login with these details.
    Username: css-tricks
    Password: test#123

    Thanks.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.