MyBB Community Forums

Full Version: How to autofocus onclick
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've got a link to an anchor that corresponds to the quick reply box on my showthread page:
Quote:<a class="bigbutton" href="#quickreply">Reply to this discussion</a>

This bit works just fine and it scrolls down to the quick reply box. My question is how would I autofocus the cursor inside the quick reply box, AFTER the user clicks on the link?

I know how to autofocus a form field when the page is loaded, but no idea how to do it onclick.

Thanks!
I THINK this should work:

<a class="bigbutton" href="#quickreply" onclick="document.findElementById('someUniqueId').focus(); return false;">Reply to this discussion</a>
You actually don't even need the anchor in my experience, though it's good to have as a fallback. Here's what I'm using to accomplish this.

<a href="#quick_reply_form" onclick="javascript:document.getElementById('message').focus()" class="button bigbutton"><span class="icon-comment"></span> post a reply</a>
Thanks to both of you!
jQuery if you need:

<script type="text/javascript">
$(document).ready(function() {
$('#bigbutton').focus();
});

You may need to set bigbutton as id instead of class.