I'm very new to javascript and am trying to make a spinner which increments a text input by + or - 1 based on what button is pressed.
I got this working if you change the text input id to a number, but when you use text, it will not call the function onmousedown.
I have tried changing ship1 to 'ship1' and "ship1", any help would be very much appreciated.
Dustin
Code: Select all
<html>
<head>
<script language="javascript">
function addShip( InputId ){
var amt = document.getElementById( InputId ).value;
document.getElementById( InputId ).value++;
if(amt >= 100)
{
document.getElementById( InputId ).value = 100;
}
}
function subShip( InputId ){
var amt = document.getElementById( InputId ).value;
document.getElementById( InputId ).value--;
if(amt <= 0)
{
document.getElementById( InputId ).value = 0;
}
}
</script>
</head>
<body onmouseup="if(window.on)clearInterval(on);">
<form>
<input type="text" id="ship1" value="0">
<input type="button" value=" /\ " onmousedown="on=setInterval('addShip(ship1)',1);" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;" >
<input type="button" value=" \/ " onmousedown="on=setInterval('subShip(ship1)',1);" style="font-size:7px;margin:0;padding:0;width:20px;height:13px;" >
</form>
</body>
</html>