By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Let-click send to need right?

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.