Hi,
I've a pretty simple piece of code that adds or subtracts the number in a field when when a user clicks up (it adds) and click down (it subtracts).
This is all simple enough but I got to thinking that it would be nice if the event continues to happen when the user the mouse holds down.
Ideally there would be an initial movement of add/subtract that would have perhaps a 1.5 second pause simulating a click. It would then add(or subtract) continually at a reasonable rate i.e. you could just about stop it on the right number.
I'm guessing it would be something along the lines on onMousedown event starts and continues till onMouseUp, however, this is all very new territory for me so I'm not very sure about this at all.
The code so far is as follows
Any help would be much appreciated.
Richard
I've a pretty simple piece of code that adds or subtracts the number in a field when when a user clicks up (it adds) and click down (it subtracts).
This is all simple enough but I got to thinking that it would be nice if the event continues to happen when the user the mouse holds down.
Ideally there would be an initial movement of add/subtract that would have perhaps a 1.5 second pause simulating a click. It would then add(or subtract) continually at a reasonable rate i.e. you could just about stop it on the right number.
I'm guessing it would be something along the lines on onMousedown event starts and continues till onMouseUp, however, this is all very new territory for me so I'm not very sure about this at all.
The code so far is as follows
Code:
<html>
<head>
<title>Add subtract value</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function addOne(){
var valField = document.forms[0].elements["selectionNumb"].value;
var newvalField = parseFloat(valField) + 1;
if (newvalField < 10) {
document.forms[0].elements["selectionNumb"].value = newvalField;
}
}
function reduceOne(){
var valField = document.forms[0].elements["selectionNumb"].value;
var newvalField = parseFloat(valField) - 1;
if (newvalField > -1) {
document.forms[0].elements["selectionNumb"].value = newvalField;
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input name="selectionNumb" id="selectionNumb" type="text" value="0" size="3" maxlength="3" />
<a href="#" onMouseDown="addOne()">up</a> | <a href="#" onMouseDown="reduceOne()">Down</a>
</form>
</body>
</html>
Any help would be much appreciated.
Richard