473,796 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding 1 to form field with button

1 New Member
Hi,

I´m building a form and decided to throw myself at some Javascript, even though im definetely no expert. Thats why i now need help :-/

I´m building a fairly simple HTML form where the user types in data about himself.

One of the form fields contain the number 0 which can then be changed by the user manually (which then results in some calculations etc...). However i would very much like to have a button that is able to add 1 to the form field when it is clicked - also it would be nice to have one that subtracts 1.

I am guessing i need a piece of code that adds +1 (or subtracts) from the value of the form field? But how i would do that i have no idea. I hope someone here can help me out?

Thx for the help and a great place to learn Javascript :-)
Mar 26 '08 #1
1 1771
johnhjohn
43 New Member
Here is an example that will add or subtract one:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script language="javascript" type="text/javascript">
  5.  var current;
  6.  function add_subtract(numb)
  7.  {
  8.    current = parseInt(document.getElementById("number").value);    // gets value from text  (parseInt gets first occurrence of a number from text)
  9.    current+=numb;    // adds variable numb to current
  10.    document.getElementById("number").value = current;    // puts new value into text
  11.  }
  12. </script>
  13.  
  14. </head>
  15. <body>
  16. <input type="text" id="number" value="0">
  17. <input type="button" value="Add One" onclick="add_subtract(1)">
  18. <input type="button" value="Subtract One" onclick="add_subtract(-1)">
  19.  
  20. </body>
  21. </html>
  22.  
I hope I helped.
Mar 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2835
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can some one tell me what I'm doing wrong? it looks like this: var tbl=document.tbl; var frm=document.frm; var newcell=document.createElement("TD");
11
14414
by: Bobbak | last post by:
Hello All, I have these tables (lets call it ‘EmpCalls', ‘EmpOrders', and ‘Stats') that each contain the list of EmployeeIDs, I want to be able to create a Module in which I could call in my VB form (by clicking and command button)that will add a column (field) to each table and label it with the current date that is specified in my form. Does anyone know how I can go about doing this? Any suggestion will be greatly appreciated.
6
2507
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
2
2622
by: David | last post by:
Hi, I have an order form which has a field 'ProductID'. This form has a button on each record to open a new form linked by ProductID. This new form is a continuous form and obviously, only displays the records associated with that ProductID. Basically this is part of a Product Packing Pick System. From my products table, each product has a set default amount of items which
3
4886
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
5
6532
by: johnny | last post by:
hi all, I wonder if I could do the following task in PHP before searching for javascript which I prefer not to have in my code: I have a form to create new tables in a database and, since I can't know how many columns needs each table, I want to load the page with a single text field in the form and then with a button adding more fields to the form if required.
5
2098
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script rather than using the html <form> and related tags. Can this be done to support both IE, Firefox? Any code snippets or samples showing how to do this would be fantastic. Thanks! --- Mike
1
5928
by: Catriona | last post by:
I am developing an Access application where users insert bill records for an electricity account by clicking on a new button. The required workflow is 1) New button clicked 2) New record appears with some field populated per defaults for account and some based on previous records - eg dates 3) Save button clicked 4) Record validated and saved if it passes validation. I have three issues as follows
0
1940
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship is a one to many from the main table to the sub table.
3
2638
by: Celal | last post by:
Hi, I couldn't get around a problem about decimal rounding up when adding a record to a table from a form by programming a button. I have an invoice form where the grand total is a calculated text field. The command button "cmdProcess" is supposed to add some fields (customer no, invoice date, grand total (as receivable), currency etc) to a table which keeps track of customer transactions. However, the decimals of grand total field is rounded...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.