Moving cursor programmatically from one page to another using JavaScript
I have 2 pages on the screen (actually more since this is a kind of proprietary web application with multiple frames and I can't really figure out the whole structure)
I entered search criteria on a page, I hit Enter on my keyboard, the search is performed, and another view is populated with data. There is a "Confirm button on this second view and the user must click on it".
Id, as a user, press "Enter" on the keyboard and "Confirm Execution".
If I click on a field on this second view and I press Enter, a confirmation will be performed, so I need to move the mouse focus from the first page to another.
How can I achieve this programmatically?
I have tried the following
<SCRIPT FOR=window event=onload language="JScript">
var focusField = "<%= controller->component_id %>" + '_' + 'NUMBER';
document.getElementById(focusField).focus();
</SCRIPT>
The cursor is still in the input field on the first page.
<SCRIPT FOR=window event=onload language="JScript">
var focusField = "<%= controller->component_id %>" + '_' + 'NUMBER';
alert(document.getElementById(focusField).value);
document.getElementById(focusField).focus();
</SCRIPT>
The field value is displayed so that the code goes there
The cursor is still in the input field on the first page
<SCRIPT FOR=window event=onload language="JScript">
var focusField = "<%= controller->component_id %>" + '_' + 'NUMBER';
document.getElementById(focusField).focus();
alert('1');
alert('2');
</SCRIPT>
The cursor is still in the input field on the first page
<SCRIPT FOR=window event=onload language="JScript">
var focusField = "<%= controller->component_id %>" + '_' + 'NUMBER';
alert('1');
document.getElementById(focusField).focus();
alert('2');
</SCRIPT>
And the cursor "brought out" the input field somehow "miraculously" and 'Enter' works on the 2nd page !!!
What for?
Of course this is not a solution, but I'm wondering why using warnings (but 2 not 1) achieves my goal of moving the mouse focus.
thank
source to share
I found a way to make it work
<SCRIPT FOR=window event=onload language="JScript">
function setFocus()
{
var focusField = "<%= controller->component_id %>" + '_' + 'CUSTOMER_STRUCT.BP_NUMBER';
document.getElementById(focusField).focus();
}
window.setTimeout('setFocus()', 40);//1,10,20,30 do not work
</SCRIPT>
Any explanations for this?
It works on my desktop. Maybe it won't work on other workstations (i.e. the interval should be higher)?
source to share