PDA

View Full Version : Js number box. With up down buttons.



tomagig
01-10-2011, 12:15 AM
1) Js Numeric Up Down

2) Drew Toma

3) This is a text bot that only allows numbers to be entered, also if it's focused and the up or down arrow are pressed it will add or subtract from the box. There are then two (removable) buttons to add or subtract from the text box.

4) URL TO CODE:
http://drewtoma.com/code/DynamicDriveCode
OR
http://drewtoma.com/?p=52

May I say I love dynamic drive, and if there is a problem with my code please tell me what I must fix to get it uploaded here.

tomagig
01-10-2011, 12:36 AM
Please hold off review I have noticed a error with my code. Sorry for the inconvenience.

tomagig
01-10-2011, 12:57 AM
Ok so I have updated the broken code.

The new link is: http://drewtoma.com/code/DynamicDriveCode.html.

ChangeLog=
Fixed up down.
Removed using the - and + key.
Made code run off of the text box id. To use multiple on one page.

Again I am very sorry for the delay. If there is any other problem please tell me.

Nile
01-10-2011, 01:02 AM
Make it so that you can hold the + or - button and it will increase every 20 milliseconds that you're holding it for. Do something like:


var c;
element.onmousedown = function() {
c = setTimeout(function(){ el.value += 1; }, 20);
}
element.onmouseup = funciton(){
clearTimeout(c);
}

tomagig
01-10-2011, 01:06 AM
I originally had it like that but the + symbol is shift that key, and js registers the shift. But what I had was if the = was entered its the same key but different symbol.
What was happening was it would enter the = the box, I could do a void(0). I will do that.
Thanks,
-tomagig

tomagig
01-10-2011, 02:24 AM
I just could not get the - + keys to work. What was happening is when you focus the box and click + OR - it would enter into the box. And nothing I did would strip that or ignore it. Im sorry, but the code is ready to be reviewed.

Nile
01-12-2011, 12:26 AM
Use return: false; to get it from entering a + or - sign in the textbox (onkeypress).

tomagig
01-12-2011, 11:44 PM
Use return: false; to get it from entering a + or - sign in the textbox (onkeypress).

That disables all functionality. :confused:

Nile
01-13-2011, 12:45 PM
Do like:


window.onkeypress = function(e){
if(e.blah == 45) { //if the key == the + or - key (45 is just a place holder)
input++;
return false;
}
}