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

Why does event.button always = 0

P: n/a
I've been staring at this a while, and I haven't had much luck with it.
So I figure I'll try Usenet.

No matter what I try, it seems the event.button property is always "0".
Here is my test case HTML, can anyone tell me what I am doing wrong?

Thanks in advance.

<HTML>
<script language="javascript">

function log()
{
debugWrite("button: " + event.button);
debugWrite("keyCode: " + event.keyCode);
debugWrite("type: " + event.type);
}
function debugWrite(testString) {
document.all.debug.value = document.all.debug.value + (new
Date()).getHours() + ":" + (new Date()).getMinutes() + ":" + (new
Date()).getSeconds() + ":" + (new Date()).getMilliseconds() + " - " +
testString + "\r\n";
}

</script>

</HEAD>
<body class="gradient" bottomMargin="0" leftMargin="0" topMargin="0"
rightMargin="0" MS_POSITIONING="FlowLayout"
onload="document.all.debug.value='';">
<form>
<input type="text" name="test" id="test" size="20" onClick="log();"
onFocus="log();" onKeyDown="log();">
<input type="button" name="test" id="button" size="20"
onClick="log();" onFocus="log();" onKeyDown="log();">
<br>
<br>
<textarea id="debug" style="width:700px; height:500px"></textarea>
</form>
</body>
</HTML>

Sep 30 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
jo*********@gmail.com wrote:
I've been staring at this a while, and I haven't had much luck with it.
So I figure I'll try Usenet.

No matter what I try, it seems the event.button property is always "0".


Given that a click occurs when the button is released, that may not be
unreasonable. That said, under Opera it is 1.

--
S.C.

Oct 1 '05 #2

P: n/a
JRS: In article <11**********************@g43g2000cwa.googlegroups .com>
, dated Fri, 30 Sep 2005 11:44:33, seen in news:comp.lang.javascript,
jo*********@gmail.com posted :
function debugWrite(testString) {
document.all.debug.value = document.all.debug.value + (new
Date()).getHours() + ":" + (new Date()).getMinutes() + ":" + (new
Date()).getSeconds() + ":" + (new Date()).getMilliseconds() + " - " +
testString + "\r\n";
}


AFAIK, this does not address the problem that you are asking about : but
new Date() should be called only once to determine a date/time, since
it changes continually.

function debugWrite(testString) { var D = new Date()
document.all.debug.value +=
D.getHours() + ":" + D.getMinutes() + ":" + D.getSeconds() + ":" +
D.getMilliseconds() + " - " + testString + "\r\n";
}

function debugWrite(testString) { with (new Date())
document.all.debug.value +=
getHours() + ":" + getMinutes() + ":" + getSeconds() + ":" +
getMilliseconds() + " - " + testString + "\r\n";
}

For public use, the third colon should be a decimal point, and the
fields should have leading zeroes if small.

Code posted to News should not be wrapped by the posting agent; it
should be posted in directly executable form. It helps to use two
spaces, rather than tab, to indent. See newsgroup Wednesday FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 1 '05 #3

P: n/a
jo*********@gmail.com a écrit :
I've been staring at this a while, and I haven't had much luck with it.
So I figure I'll try Usenet.

No matter what I try, it seems the event.button property is always "0".
Here is my test case HTML, can anyone tell me what I am doing wrong?

Thanks in advance.

<HTML>
<script language="javascript">

Language is deprecated. Type has replaced language and is
backward-compatible too. So, best is

<script type="text/javascript">
function log()
{
debugWrite("button: " + event.button);
debugWrite("keyCode: " + event.keyCode);
debugWrite("type: " + event.type);
}
function debugWrite(testString) {
document.all.debug.value = document.all.debug.value + (new
Date()).getHours() + ":" + (new Date()).getMinutes() + ":" + (new
Date()).getSeconds() + ":" + (new Date()).getMilliseconds() + " - " +
testString + "\r\n";

You can safely replace document.all with document.getElementById if you
want to support all modern browsers and MSIE 5+.

document.getElementById("debug").value
will do the trick.

http://www.mozilla.org/docs/web-deve...tml#dom_access

}

</script>

</HEAD>
<body class="gradient" bottomMargin="0" leftMargin="0" topMargin="0"
rightMargin="0" MS_POSITIONING="FlowLayout"
All these attributes are proprietary ones, not recognized by non-MSIE
agents.
onload="document.all.debug.value='';">
<form>
<input type="text" name="test" id="test" size="20" onClick="log();"
onFocus="log();" onKeyDown="log();">
<input type="button" name="test" id="button" size="20"
onClick="log();" onFocus="log();" onKeyDown="log();">
<br>
<br>
<textarea id="debug" style="width:700px; height:500px"></textarea>
</form>
</body>
</HTML>



"button of type unsigned short, readonly
During mouse events caused by the depression or release of a mouse
button, button is used to indicate which mouse button changed state. The
values for button range from zero to indicate the left button of the
mouse, one to indicate the middle button if present, and two to indicate
the right button."
http://www.w3.org/TR/2000/REC-DOM-Le...seEvent-button

So, if you mouse-click inside the textarea with the left mouse button,
then it should be zero. If you type in the textarea, then event.button
should be zero the last recorded value of button.

Gérard
--
remove blah to email me
Oct 2 '05 #4

P: n/a
Stephen Chalmers a écrit :
jo*********@gmail.com wrote:
I've been staring at this a while, and I haven't had much luck with it.
So I figure I'll try Usenet.

No matter what I try, it seems the event.button property is always "0".

Given that a click occurs when the button is released, that may not be
unreasonable. That said, under Opera it is 1.

--
S.C.


It is 0 with left mouse button click.

Opera 8.5 is DOM 2 Events compliant. See for yourself:

http://www.din.or.jp/~hagi3/JavaScri...MouseEvent.htm

Nota bene: you need to allow right-click in
Tools/Preferences.../Advanced tab/Content category/Javascript Options...
button/Allow right-click scripting checkbox must be checked

Gérard
--
remove blah to email me
Oct 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.