Click to See Complete Forum and Search --> : keeping input element focused after right click


sharapov
10-16-2003, 05:22 PM
I am designing an Intranet application. In my application I need the focus always be on input text field. I also need to disable the context menu. I am able to achieve all that with the code below. However, when I right click anywhere on the page I loose focus on my input field. The only way I can bring it back if I click anywhere on the page with the left button. How can I keep focus on my input element when I right-click the page?



<html>
<head>
<title></title>
</head>

<body onclick="document.oForm.searchval.focus()" onload="document.oForm.searchval.focus()" oncontextmenu="return false">

<form name="oForm">
<input onblur="this.focus();" type="text" name="searchval" size="20"><br><br>
<input type="text" name="T2" size="20"><br><br>

<button>Test</button>
</form>

</body>
</html>

gunther_mcfly
10-16-2003, 06:42 PM
<html>
<head>
<script language="javascript">
document.oncontextmenu=new Function("document.oForm.searchval.focus();return false");
</script>
<title></title>
</head>
<body onload="document.oForm.searchval.focus()" onclick="document.oForm.searchval.focus()">
<form name="oForm">
<input type="text" name="searchval" size="20"><br><br>
<input type="text" name="T2" size="20"><br><br>

<button>Test</button>
</form>

</body>
</html>

sharapov
10-16-2003, 06:47 PM
gunther_mcfly,

Thank you for your reply. It looks like it might work!!!!

gunther_mcfly
10-16-2003, 07:23 PM
you're welcome, it's what i'm here for :)

sharapov
10-17-2003, 01:16 PM
gunther_mcfly,

I found a little bug in the code that you have proposed. If you double click with the right mouse button, the text field looses focus anyway! Any suggestions?

Thanks.

sharapov
10-17-2003, 02:12 PM
I have solved the problem that I had. Here is the solution for those who are interested:



<html>
<head>
<title></title>
</head>
<body onclick="document.oForm.searchval.focus()"
onload="document.oForm.searchval.focus()"
oncontextmenu="if(document.all)document.body.focus();return false">
<form name="oForm">
<input onblur="this.focus();" type="text" name="searchval" size="20"><br><br>
<input type="text" name="T2" size="20"><br><br>
<button>Test</button>
</form>
</body>
</html>