Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2007, 04:35 PM   PM User | #1
tuck80
New to the CF scene

 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tuck80 is an unknown quantity at this point
Adding in a text box

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
tuck80 is offline   Reply With Quote
Old 02-08-2007, 04:47 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
onclick="this.form.yourtextboxname.value = parseInt(this.form.yourtextboxname.value)+1;"

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

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 02-08-2007, 05:00 PM   PM User | #3
tuck80
New to the CF scene

 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tuck80 is an unknown quantity at this point
Where do I add this- I have created a form and put a text box in it with the name text
tuck80 is offline   Reply With Quote
Old 02-08-2007, 05:15 PM   PM User | #4
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
<body>
<form>
<input type="text" name="t1"><br>
<input type="button" onclick="this.form.t1.value = parseInt(this.form.t1.value)+1;">
</body>
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 02-08-2007, 05:21 PM   PM User | #5
tuck80
New to the CF scene

 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
tuck80 is an unknown quantity at this point
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)
tuck80 is offline   Reply With Quote
Old 02-09-2007, 02:30 PM   PM User | #6
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Like I said, you have to add the check for isNaN

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

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 02-09-2007, 04:07 PM   PM User | #7
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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);">

Last edited by tonyp12; 02-09-2007 at 05:09 PM..
tonyp12 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:49 PM.


Advertisement
Log in to turn off these ads.