trying to use javascript to keep adding a number

They have: 1,587 posts

Joined: Mar 1999

um, i'm trying to figure out how to keep adding to a number. url is below:

http://www.strategy-war.com/all1.htm

thx in advance Smiling

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Here is some code that I took from something I wrote (which is currently waiting for some beta testing, anyone interested?). I tested this counter, it works fine. The only draw back is that this uses a text box (which I 'cloacked').

<input type=text size=5 name=Size value="0" style="border=0; text-align=right">
<input type=button value=" -- " onClick="theSize=Size.value;theSize=theSize-10;Size.value=theSize;">
<input type=button value=" - " onClick="theSize=Size.value;theSize--;Size.value=theSize;">
<input type=button value=" + " onClick="theSize=Size.value;theSize++;Size.value=theSize;">
<input type=button value=" ++ " onClick="theSize=Size.value;for(i=1;i<=10;i++){theSize++;}Size.value=theSize;">
'

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 1,587 posts

Joined: Mar 1999

the number starts at 11. a click then makes the number 12, but i can't get it to go any higher than 12, hmm.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

look at your source AFTER you click...
your javascript is gone, that's your problem

They have: 1,587 posts

Joined: Mar 1999

yeah, any idea how i fix that?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

no...

you can look at these JS toys I've written, but they both use form elements (like the example I have above).
Guess The Number
Random Colors

Have you tried my above code? you should, the textbox is invisible, and it works. Or won't it work for your specific need?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 1,587 posts

Joined: Mar 1999

thx, it looks like i may be able to disect those scripts to give me an idea of how to do what i want to do.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

post the solution here if you find one... I tried playing with it for a little while, but was getting nowhere.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi fairhousing,

I'm not sure what you are attempting, nor if this is related to your other post. However, if you are willing to use a textbox, you can use the following:

<script language='javascript'>

function add(formObj, incrementVal)
{
formObj.numField.value += incrementVal;
}
</script>

;
;

Notes:
1) The blur() statement will prevent the user from changing the contents of the field.
2) The form object and increment value are passed as parameters. You can remove the parameters and hardcode everything, but it's much more reusable this way.
3) I'm leaving the conversion of text to integer to you. Smiling

Vinny

Where the world once stood
the blades of grass cut me still

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

add:
style="border=0; text-align=right"
and the 'box' disapears...

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Max,

Nice Smiling but Netscape doesn't like 'style' commands in html tags Sad

Vinny

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

oops..

I don't have NN installed, so I know I'm missing a lot of this cross-browser stuff. Well, live and learn. thx

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.