473,239 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,239 software developers and data experts.

Let-click send to need right?

In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to get the focus no matter where on the page the user clicks be it right-click or left-click. Right now there is no context menu when the user right-clicks. Do you think that's the problem? Any ideas how to get this right-click left-click Input box get's focus with JavaScript? Thanks.

Here's what I have so far:

<script type="text/javascript" for="document" event="onclick">
<!-- Begin
//window.event.srcElement.cancelBubble = true;
//window.event.returnValue = true;
if (frm1.UID.value == ''){
document.frm1.UID.focus();
}
// End -->
</script>

The UID is the ID for the Input box; frm1 is the name of the Form; this script resides within the <HEAD> tag.

--
George Hester
__________________________________
Jul 20 '05 #1
8 1982
On 12/28/03 1:33 AM, in article BO*******************@twister.nyroc.rr.com,
"George Hester" <he********@hotmail.com> wrote:
In a page I have when the user left-clicks the page a Input box for a form
gets the focus. But if the user right-clicks the page the Input box is not
getting the focus. I'd like the Input box to get the focus no matter where on
the page the user clicks be it right-click or left-click. Right now there is
no context menu when the user right-clicks. Do you think that's the problem?


Possibly. Where is the code you are using for that? If you are returning
false to the onclick event within your no-context-menu code, then that's
probably what's canceling the event.

--
mattwarden
mattwarden.com

Jul 20 '05 #2
"George Hester" <he********@hotmail.com> writes:

(please keep your lines below ~72 characters. The following was one long
line).
In a page I have when the user left-clicks the page a Input box for
a form gets the focus. But if the user right-clicks the page the
Input box is not getting the focus. I'd like the Input box to get
the focus no matter where on the page the user clicks be it
right-click or left-click.
That could be highly annoying.

Why do you want that? If it is to give focus to the input element when
the user gives the browser focus, I would use the window.onfocus handler.
Right now there is no context menu when the user right-clicks. Do
you think that's the problem?
Tampering with standard browser behavior is almost always a problem
for the user. If I right-click, I expect the context menu to appear
(and in my browser, it will, no matter what you try :).

However, I can't see how your code stops the context menu. Are you
sure the code you posted is the correct one? Can you show us a page
that has the problem?
Any ideas how to get this right-click left-click Input box get's
focus with JavaScript?
Let's see what you have:
Here's what I have so far:

<script type="text/javascript" for="document" event="onclick">
So, this code is supposed to work in Internet Explorer only. The
"for" and "event" attributes are proprietary Microsoft inventions, and
won't work in any other browser, as is "window.event". To get the
samme effect in both IE and other browsers, I would do:

<script type="text/javascript">
document.onclick = function (event) {
event = event || window.event; // IE sucks
/// your code, but with "event" instead of "window.event".
}
</script>
<!-- Begin
HTML-like comments are not necessary in Javascript.
//window.event.srcElement.cancelBubble = true;
That would be
window.event.cancelBubble = true;
in IE.
//window.event.returnValue = true;
if (frm1.UID.value == ''){
Again, a safer, cross browser, method of referring to a form control is:
if (document.forms['frm1'].elements['UID'].value == '') {
Just using the form name as a global value is also IE specific.
document.frm1.UID.focus();
}
// End -->
</script>

The UID is the ID for the Input box; frm1 is the name of the Form;
this script resides within the <HEAD> tag.


That means that the user can click the page between the time when the
handler is assigned and the form is loaded. It is not dangerous, but
will give a Javascript error. It would be safer to assign the handler
after the form has been loaded.
How I would do it:
---
<script type="text/javascript">
document.onclick = function(event) {
// event = event || window.event; // if you need it.
var ctrl = document.forms['frm1'].elements['UID'];
if (ctrl.value == "") {
ctrl.focus();
}
}
</script>
---
and I would put this code right after the </form> of <form id="frm1" ...>.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
On Sun, 28 Dec 2003 14:22:25 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
The
"for" and "event" attributes are proprietary Microsoft inventions, and
won't work in any other browser, as is "window.event". To get the
samme effect in both IE and other browsers, I would do: event = event || window.event; // IE sucks


If you believe this is a bad design for events in js then can you
please tell the SVG WG, who currently have it in a draft: (evt not
event, but that's the only difference)

http://www.w3.org/TR/SVG12/#WindowObject

ww*****@w3.org of course.

Jim.

--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4
ji*@jibbering.com (Jim Ley) writes:
On Sun, 28 Dec 2003 14:22:25 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
event = event || window.event; // IE sucks


If you believe this is a bad design for events in js then can you
please tell the SVG WG, who currently have it in a draft: (evt not
event, but that's the only difference)


I hadn't really thought about it, the "IE sucks" that I habitually
add, refers to IE's lacking support for DOM 2 Events, where the event
is passed an argument.

Maybe a little ironic, since I assign the event handler directly to
the "onclick" property instead of using the DOM 2 Events method
"addEventListener", but guess who doesn't support that either :).

However, having thought about it for not very long, I do believe
it is a bad design, because globally variables like that prohibits
multithreading. While current browsers are quite singlethreaded in
their Javascript execution, adding design that makes it impossible
to change that is ... well, bad design.
http://www.w3.org/TR/SVG12/#WindowObject
Looking a this, it seems the only use of "evt" is in HTML attributes,
e.g.,

<pushButton xmlns="http://bar.example.org/buttons"
action="myCallback(evt)"/>

The actual handler function then uses its argument instead of the
global variable. I think this is using the same thinking that the
makers of IE used: The variable must be available to event handler
attributes, so we make it global instead of making a new one for each
event.

Generally, I don't like the way the SVG DOM is being made. It is not
very progressive.
Why call the global object "window" at all? I would much have
preferred separate global and window objects (as I would in normal
browsers too). They are putting too much crap into the global object.
ww*****@w3.org of course.


Is what? A mailing list, a mail address for comments, or?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
On Sun, 28 Dec 2003 15:00:53 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
http://www.w3.org/TR/SVG12/#WindowObject
Looking a this, it seems the only use of "evt" is in HTML attributes,
e.g.,


In their examples yes, but, it's still there in the IDL.
Generally, I don't like the way the SVG DOM is being made. It is not
very progressive.


They're not really making it, they're rubber stamping and fixing the
de-facto ones...
ww*****@w3.org of course.


Is what? A mailing list, a mail address for comments


It's both. and I'd urge people to get involved, the W3's script
knowledge is unfortunately not what it could ideally be.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #6
Actually I think I should remove the script I had to remove the context-menu. I don't think it works right. But here it is:

<!-- Begin
//Disable right click script III- By Muzaffer Mohammad (mu***@muzzu.ca.tc)
//For full source code, visit http://www.muzzu.ca.tc
var message="";

function clickIE(){
if (document.all){
(message);
alert('message = ' + message);
return false;
}
}

function clickNS(e){
if(document.layers||(document.getElementById&&!doc ument.all)){
if (e.which==2||e.which==3){
(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
} else{
//alert(clickIE);
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
}

document.oncontextmenu=new Function("return false")

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect;
document.onclick=reEnable;
}
// End -->

I could just use the attribute in the Body tag:

onContextMenu="return false"

and that would serve my purpose just as well. Do you think then I can capture the right-click then and if so how?

Thanks for the reply. There is only one type of browser that will be accessing this page and that is IE from 5 on up.

--
George Hester
__________________________________
"Matthew Warden" <ne********@mattwarden.com> wrote in message news:BC14044F.792%ne********@mattwarden.com...
On 12/28/03 1:33 AM, in article BO*******************@twister.nyroc.rr.com,
"George Hester" <he********@hotmail.com> wrote:
In a page I have when the user left-clicks the page a Input box for a form
gets the focus. But if the user right-clicks the page the Input box is not
getting the focus. I'd like the Input box to get the focus no matter where on
the page the user clicks be it right-click or left-click. Right now there is
no context menu when the user right-clicks. Do you think that's the problem?


Possibly. Where is the code you are using for that? If you are returning
false to the onclick event within your no-context-menu code, then that's
probably what's canceling the event.



--
mattwarden
mattwarden.com

Jul 20 '05 #7
Lesse:

'That could be highly annoying." - There is nothing else on the page so there is no reason for anything else to be done on the page except put something in the Input box. It is a logon page and the user must enter a User ID first before doing anything else except leave. Everything but that disabled at page load.

Now I am not too concerned about making it multi-browser friendly but I will keep it in mind..

Finally I suspect you have quite a few jewels in what you said so it'll take me some time to digest it. Thanks.

--
George Hester
__________________________________
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message news:pt**********@hotpop.com...
"George Hester" <he********@hotmail.com> writes:

(please keep your lines below ~72 characters. The following was one long
line).
In a page I have when the user left-clicks the page a Input box for
a form gets the focus. But if the user right-clicks the page the
Input box is not getting the focus. I'd like the Input box to get
the focus no matter where on the page the user clicks be it
right-click or left-click.


That could be highly annoying.

Why do you want that? If it is to give focus to the input element when
the user gives the browser focus, I would use the window.onfocus handler.
Right now there is no context menu when the user right-clicks. Do
you think that's the problem?


Tampering with standard browser behavior is almost always a problem
for the user. If I right-click, I expect the context menu to appear
(and in my browser, it will, no matter what you try :).

However, I can't see how your code stops the context menu. Are you
sure the code you posted is the correct one? Can you show us a page
that has the problem?
Any ideas how to get this right-click left-click Input box get's
focus with JavaScript?


Let's see what you have:
Here's what I have so far:

<script type="text/javascript" for="document" event="onclick">


So, this code is supposed to work in Internet Explorer only. The
"for" and "event" attributes are proprietary Microsoft inventions, and
won't work in any other browser, as is "window.event". To get the
samme effect in both IE and other browsers, I would do:

<script type="text/javascript">
document.onclick = function (event) {
event = event || window.event; // IE sucks
/// your code, but with "event" instead of "window.event".
}
</script>
<!-- Begin


HTML-like comments are not necessary in Javascript.
//window.event.srcElement.cancelBubble = true;


That would be
window.event.cancelBubble = true;
in IE.
//window.event.returnValue = true;
if (frm1.UID.value == ''){


Again, a safer, cross browser, method of referring to a form control is:
if (document.forms['frm1'].elements['UID'].value == '') {
Just using the form name as a global value is also IE specific.
document.frm1.UID.focus();
}
// End -->
</script>

The UID is the ID for the Input box; frm1 is the name of the Form;
this script resides within the <HEAD> tag.


That means that the user can click the page between the time when the
handler is assigned and the form is loaded. It is not dangerous, but
will give a Javascript error. It would be safer to assign the handler
after the form has been loaded.


How I would do it:
---
<script type="text/javascript">
document.onclick = function(event) {
// event = event || window.event; // if you need it.
var ctrl = document.forms['frm1'].elements['UID'];
if (ctrl.value == "") {
ctrl.focus();
}
}
</script>
---
and I would put this code right after the </form> of <form id="frm1" ....>.


/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #8
Hi again Lasse:

OK I went through what you described and can change what I have. I definitely don't want the javascript error if I can avoid it. I realize that not everyone has a "fast" connection and so yes many might get the javascript error I guess if I leave that in the <head> tag. So I moved it. Thanks for the information.

--
George Hester
__________________________________
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message news:pt**********@hotpop.com...
"George Hester" <he********@hotmail.com> writes:

(please keep your lines below ~72 characters. The following was one long
line).
In a page I have when the user left-clicks the page a Input box for
a form gets the focus. But if the user right-clicks the page the
Input box is not getting the focus. I'd like the Input box to get
the focus no matter where on the page the user clicks be it
right-click or left-click.


That could be highly annoying.

Why do you want that? If it is to give focus to the input element when
the user gives the browser focus, I would use the window.onfocus handler.
Right now there is no context menu when the user right-clicks. Do
you think that's the problem?


Tampering with standard browser behavior is almost always a problem
for the user. If I right-click, I expect the context menu to appear
(and in my browser, it will, no matter what you try :).

However, I can't see how your code stops the context menu. Are you
sure the code you posted is the correct one? Can you show us a page
that has the problem?
Any ideas how to get this right-click left-click Input box get's
focus with JavaScript?


Let's see what you have:
Here's what I have so far:

<script type="text/javascript" for="document" event="onclick">


So, this code is supposed to work in Internet Explorer only. The
"for" and "event" attributes are proprietary Microsoft inventions, and
won't work in any other browser, as is "window.event". To get the
samme effect in both IE and other browsers, I would do:

<script type="text/javascript">
document.onclick = function (event) {
event = event || window.event; // IE sucks
/// your code, but with "event" instead of "window.event".
}
</script>
<!-- Begin


HTML-like comments are not necessary in Javascript.
//window.event.srcElement.cancelBubble = true;


That would be
window.event.cancelBubble = true;
in IE.
//window.event.returnValue = true;
if (frm1.UID.value == ''){


Again, a safer, cross browser, method of referring to a form control is:
if (document.forms['frm1'].elements['UID'].value == '') {
Just using the form name as a global value is also IE specific.
document.frm1.UID.focus();
}
// End -->
</script>

The UID is the ID for the Input box; frm1 is the name of the Form;
this script resides within the <HEAD> tag.


That means that the user can click the page between the time when the
handler is assigned and the form is loaded. It is not dangerous, but
will give a Javascript error. It would be safer to assign the handler
after the form has been loaded.


How I would do it:
---
<script type="text/javascript">
document.onclick = function(event) {
// event = event || window.event; // if you need it.
var ctrl = document.forms['frm1'].elements['UID'];
if (ctrl.value == "") {
ctrl.focus();
}
}
</script>
---
and I would put this code right after the </form> of <form id="frm1" ....>.


/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rob Hunter | last post by:
Is there an equivalent to Scheme's LET in Python? LET creates a new binding in the current environment. For example, here's some Scheme code: (let ((x 3)) (let ((f (lambda (arg) (* arg x))))...
9
by: WindAndWaves | last post by:
Can anyone explain me the joy of let and get. Once more, I read the explanation in the help, but did not get much wiser. I seem to learn best from examples, but I did not come across any good...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
4
by: deko | last post by:
Is there any way to let users compose and run SQL from the Access interface? If I create a new query from the Database Window, select Design View and then View >> SQL View, I get a window from...
24
by: gswork | last post by:
Let's write a c program, without knowing what it does... Some of you may recall Jim Roger's excellent series of posts (on comp.programming) exploring the implementation of common software...
2
by: Chua Wen Ching | last post by:
Hi there. I had 3 questions to ask. 1) Public Event ButtonClicked(MessageBoxNumber As Integer, OKButton As Boolean, CancelButton As Boolean, ExitButton As Boolean)
3
by: ABC | last post by:
Is there any tools let me to build interaction snippets? for example, I want a interaction snippet for properties codes, it should let me select readonly, public, private, and type in variable...
12
by: Nenad Milicevic - The Aryan Serb | last post by:
Rise up and shine, white sons and daughters Rise up and shine, you gotta fight to part those waters When we swim in the light, all will be okay The black, yellow and brown man will wash away....
11
by: Alexander Vasilevsky | last post by:
Linq "into" and "let" equally??? http://www.alvas.net - Audio tools for C# and VB.Net developers
3
by: Ilyas | last post by:
Hi all In the northwind database, on the orders table, How would I get back the the number of items that exist with the following condition: ShipVia=1 ShipVia=2 ShipVia=3 I want to do...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.