473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Increment Buttons

Tormod
8
Hi there,

I realise this may sound elementary but I'm left scratching my head.

I'm trying to create a page in php with several values displayed on the page and a button next to each value which will increment the value by 1 and then ultimately save the values to the database.

I've played around with the submit button and my variables but I can't get it to work. I realise it's a bit cheeky to ask for help when I've not even got a starting point but I'm totally shtumped.

If anyone can help I'd be totally grateful.
Jul 9 '07 #1
6 2306
pbmods
5,821 Expert 4TB
Heya, Tormod.

When the User clicks on the button, do you want to save the new value right away, or do you want the User to be able to increment multiple values and/or multiple times before clicking on a 'submit' button?
Jul 9 '07 #2
Tormod
8
Ideally to save it right away. So that all the data in the database reflects what's showing on the users screen.
Jul 9 '07 #3
ak1dnar
1,584 Expert 1GB
Oops,
I think It's good to go for a ajax/php solution for this.
Is this only for testing purpose or real world project.Anyway as you wish!
You have two choices.

Before I start may I see the first page for listining those values.Is it dynamic page or static one.?

-Ajaxrand
Jul 10 '07 #4
nathj
938 Expert 512MB
Hi there,

I realise this may sound elementary but I'm left scratching my head.

I'm trying to create a page in php with several values displayed on the page and a button next to each value which will increment the value by 1 and then ultimately save the values to the database.

I've played around with the submit button and my variables but I can't get it to work. I realise it's a bit cheeky to ask for help when I've not even got a starting point but I'm totally shtumped.

If anyone can help I'd be totally grateful.
Hi Tormod,

I have done something very similar on a recent project. The difference is mine doesn't save to a database, two reasons for that. First it was on an order form and second the submit sent an email.

However, I developed two images (plus sign and a minus sign) and then set the onlcick to call the following method.
Expand|Select|Wrap|Line Numbers
  1. function setQuantity(pcID, pnOperation, pnMin, pnMax)
  2. {
  3. var lnCurrentQuantity = document.getElementById(pcID).value                                  
  4. var lnNewQuantity     = lnCurrentQuantity  
  5.     switch(pnOperation)
  6.     {                   
  7.         case 1: // increase quantity by 1 
  8.         lnNewQuantity++
  9.         if(lnNewQuantity > pnMax)
  10.         {                                
  11.             lnNewQuantity = lnCurrentQuantity
  12.         }
  13.         break;
  14.         case 2:// decrease quantity by 1
  15.         lnNewQuantity--
  16.         if(lnNewQuantity < pnMin)
  17.         {
  18.             lnNewQuantity = lnCurrentQuantity
  19.         }
  20.         break;
  21.         default:// ensuring a typed quantity remains within the parameters defined
  22.         if (lnCurrentQuantity > pnMax || lnCurrentQuantity < pnMin)
  23.         {                                     
  24.             alert("Please set the quantity between " + pnMin + " and " + pnMax + '\n' + "The quantity will now be set to 1")
  25.             lnNewQuantity = 1
  26.         }
  27.         break;
  28.     }
  29. document.getElementById(pcID).value = lnNewQuantity
  30. }
  31.  
Here is an example of the call:

MINUS
Expand|Select|Wrap|Line Numbers
  1. onclick="setQuantity('bnquantity', 2, 0, 9999);" alt="Reduce quantity by 1" title="Minus 1"> 
  2.  
PLUS
Expand|Select|Wrap|Line Numbers
  1. onclick="setQuantity('bnquantity', 1, 0, 9999);" alt="Increase quantity by 1" title="Plus 1"></td>
  2.  

The onblur was set to call it so that the value could be evaluated
Expand|Select|Wrap|Line Numbers
  1. onblur="setQuantity('bnquantity',3, 0, 9999);"
  2.  
This is fairly simplistic and could be tightened up a bit to ensure the value entered is numeric or to make the input readonly so that it cannot typed in. As a final explanation the function paramters are:
pcID: the id of the item to test and write back to
pnOperation: the operation to perform 1 = plus, 2 = minus, 3 = test the value is within the defined range
pnMin: the lowest number allowed
pnMax: the highest number allowed.

If you want to see this operation please visit the order page of my site. Please do not submit the order, unless you want any of the stuff listed. This is simply so you can see it operation.

I hope this helps and if you have questions post back.
nathj
Jul 10 '07 #5
Tormod
8
Awesome. I'll have a look at the above solution and try and amend it to fit my needs. I'll get back to you and let you know how I get on.

Sincere thanks to all who have taken the time to look at this.
Jul 10 '07 #6
nathj
938 Expert 512MB
Awesome. I'll have a look at the above solution and try and amend it to fit my needs. I'll get back to you and let you know how I get on.

Sincere thanks to all who have taken the time to look at this.
It's a pleasure. Let me know how you get on.

nathj
Jul 10 '07 #7

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

Similar topics

9
by: Mark Turney | last post by:
I was reading "Practical C++ Programming" yesterday, and it mentioned that the order of execution for post-increment and post-decrement operators was ambiguous. I had previously learned that a...
2
by: Targa | last post by:
I have a form field which displays a time in the format 5:30 PM - this time is selected from a previous page. I need to add a function to increment or deincrement the time by clicking up/down...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
13
by: kailasam | last post by:
Hello, Iam having a doubt. Which is more efficient post increment or Pre increment? I have read that preincrement is efficient than Post increment. Iam not able to think how it is? For an...
3
by: George Ter-Saakov | last post by:
What is the purpose of having Interlocked.Increment if it does not work with variable declared as volatile. Here is my problem, Interlocked.Increment increments the variable in thread safe...
2
by: john | last post by:
Is it true that if I split my access database in backend and frontend and I implement custom auto increment for the ID fields, that my database is ready to be used in a multi-user environment? I...
15
by: Ryan Liu | last post by:
Hi, Is there any known bug related to Interlocked.Increment(ref var)? My client report var's value going up and down in the client/server multile-thread application. There are about 80...
11
by: divya_rathore_ | last post by:
The code: int aaa = 100; printf("%d %d %d\n", --aaa, aaa, aaa--); printf("%d\n", aaa); prints: 99 100 100 98
8
by: bintom | last post by:
Why doe the following C++ code behaves as it does? int i; i=1; cout << (++i)++; Output: 2 i=1; cout << ++(++i); Output: 3 i=1; cout << (i++)++; Output: Error. LValue required...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.