Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.1k views
in Q2A Core by
I have a form at bottom of the page in my plugin on user profile page. Every time I submit the form, there will be a message box which is a <div> displaying the message.

But when I submit the form, it will call redirec() to refresh the page and then the focus will be set to the top of the page so that I have to scroll to the bottom to see the message box. It's not user-friendly so I wanna use js to set fucos to the message box after refreshing the page.

How can I call my js function set_focus() when refreshing the page? I cannot find a way to set this function to onload() of <body>.

Any advice? Thanks !
Q2A version: 1.6.3

1 Answer

+1 vote
by

How about $qa_content['focusid'] ? This method is used in layer not widget. 

PHP example: qa-include/qa-page-login.php (L173)

Output javascript example: (See HTML source of login page)

<script type="text/javascript">
var qa_root='.\/';
var qa_request='login';
var qa_oldonload=window.onload;
window.onload=function() {
if (typeof qa_oldonload=='function')
qa_oldonload();
 
var elem=document.getElementById('emailhandle');
if (elem) {
elem.select();
elem.focus();
}
};
</script>
In the case of modal form, this method is not usable.
...