jamescover 07-12-2004, 07:02 AM Hi:
Is there anything wrong with this simple function construction:
var x=0;
function addX(){
myForm.Num.value=x;
x++;
}
The reason I ask is, because when using an onClick handler, it doesn't seem to fire as fast as you'd expect, so that you have to pause about a full second in order to get the expected results.
-james
Is there anything wrong with this simple function construction:
Nope. It is OK.
glenngv 07-12-2004, 08:10 AM Hi:
Is there anything wrong with this simple function construction:
var x=0;
function addX(){
myForm.Num.value=x;
x++;
}
The reason I ask is, because when using an onClick handler, it doesn't seem to fire as fast as you'd expect, so that you have to pause about a full second in order to get the expected results.
-james
How are you calling the function? Are you using setTimeout or setInterval method to call it?
jamescover 07-12-2004, 05:23 PM How are you calling the function? Are you using setTimeout or setInterval method to call it?
Hi Glenn:
No, just calling the function from a button...If I press the button in succession, say, 10 times, it will count to 0-4 or so...I'm talking about intervals as slow as about 2 clicks per sec, the counter only increments by 1. But if I slow it down to 1 click per second, it increments on every click.
<script>
<!--
var x=0;
function addX(){
mForm.Num.value=x;
x++;
}
//-->
</script>
<form name="mForm">
<input type="text" name="Num" size="5" />
<input type="button" value="x++" onClick="javascript:addX();" />
</form>
Thanks for responding too Kor.
-james
Basscyst 07-12-2004, 05:42 PM Hello,
Try adding an ondblclick="addX()" to the button. Should solve the problem.
Basscyst
Choopernickel 07-12-2004, 06:16 PM Gecko browsers respond to clicks much differently than IE does: the order of event execution for a double click in Gecko is mousedown
mouseup
click
mousedown
mouseup
click
dblclick
In IE, it's missing the second click, so its execution order is onmousedown
onmouseup
onclick
onmousedown
onmouseup
ondblclick
Wrap the ondblclick event assignment in an if(document.all) branch and you should be set.
jamescover 07-12-2004, 10:36 PM Basscyst--Try adding an ondblclick="addX()" to the button. Should solve the problem.
Choopernickel-- Wrap the ondblclick event assignment in an if(document.all) branch and you should be set.
Thanks, for responding.
Double click works, but are you saying that I can't achieve the same results in IE 5.0 using onClick? I want to increment the value of x on every [single] click...
thanks,
-james
glenngv 07-13-2004, 01:58 AM Try using onmousedown instead of onclick or ondblclick
<input type="button" value="x++" onmousedown="addX();" />
jamescover 07-13-2004, 04:18 AM Try using onmousedown instead of onclick or ondblclick
<input type="button" value="x++" onmousedown="addX();" />
Sorry, Glenn, same result...
I finally got it sorted, but I think it's something to keep in the back of your mind, if your using js for calculations in a shopping cart, etc.
<script>
<!--
x=0;
function addX(){
mForm.Num.value=x;
x++;
}
//-->
</script>
<form name="mForm">
<input type="text" name="Num" size="5" />
<input type="button" value="x++" onmousedown="javascript:this.focus();" onmouseup="javascript:addX();" />
</form>
That's the only way it work increment on every [single] click in IE 5.0...
Thanks to everyone who contributed.
-james
]|V|[agnus 07-13-2004, 04:22 AM edit: i misread in haste... nevermind my original comment. i saw "onmousedown" and "onmouseup" instead of "onfocus" and "onmouseup" :(
jamescover 07-13-2004, 04:30 AM so you're going the completely counter-intuitive route just to satiatie IE5? why? doesn't that method result in +2 per click for most others?
I'm not suggesting that this x-browser cure-all, but that it is something to keep in the back of your mind (i.e, this strange behavior in IE 5.0) when building such an app....
Although I do have a personal browser preference, I always try to code for NN/IE 4+ browsers, and not impose my own preferences on my viewers.
-james
]|V|[agnus 07-13-2004, 04:34 AM see above
jamescover 07-13-2004, 05:45 AM Hi |V|[agnus
Not a problem.
I wasn't trying to say anything beyond, I code/design for someone besides myself. For this reason, I intentionally don't use the lastest or the best browser(s), i.e., I don't do this out of personal preference. And I never assume that because something works in my browsers, it will work in all browsers.
I didn't think that this would result in increments of 2 in other browsers, but I wasn't taking that for granted...
Cheers :)
-james
|
|