...

View Full Version : Adding in a text box



tuck80
02-08-2007, 04:35 PM
I struggling to create/find some code that will do the following

A text starts with the number "0" in it and when the user either clicks a button at the side of the box or click in the box (only one way is required) the number changes to 1 if pressed again it changes to 2 and so one. If any one could help with this it would be great

Thank you

nikkiH
02-08-2007, 04:47 PM
onclick="this.form.yourtextboxname.value = parseInt(this.form.yourtextboxname.value)+1;"

Add a check for isNaN if you don't control the value.

tuck80
02-08-2007, 05:00 PM
Where do I add this- I have created a form and put a text box in it with the name text

nikkiH
02-08-2007, 05:15 PM
<body>
<form>
<input type="text" name="t1"><br>
<input type="button" onclick="this.form.t1.value = parseInt(this.form.t1.value)+1;">
</body>

tuck80
02-08-2007, 05:21 PM
This kinda works, when 1 first press the button it says NaN if I delete this and put the number 1 in it then press the button it adds 1 (every time I click)

nikkiH
02-09-2007, 02:30 PM
Like I said, you have to add the check for isNaN

A simple google search will show you how to do this.

tonyp12
02-09-2007, 04:07 PM
Checks for NaN

By using the OR statment '||'

( is a number || instead )

<input type="text" name="t1"><br>
<input type="button" value="+1" onclick="this.form.t1.value = (parseInt(this.form.t1.value)+1 || 1);">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum