I've got a weird situation where people have to select a quantity but it can only be in increments of 25. Instead of having a drop down box of 25, 50, 100, etc..., I wanted to have a basic text field where someone can input a number and it'll automatically round it up or down to the nearest 25.
Is this possible? Does anyone have any idea on how to do it?
I've got a weird situation where people have to select a quantity but it can only be in increments of 25. Instead of having a drop down box of 25, 50, 100, etc..., I wanted to have a basic text field where someone can input a number and it'll automatically round it up or down to the nearest 25.
Is this possible? Does anyone have any idea on how to do it?
I started to suggest the modulus operator, but then found this:
PHP Code:
//found on adminzone.com
function round_nearest($no,$near)
{
return round($no/$near)*$near;
}
Now I may be pushing things but is there a way to make it round to the nearest 25 if the quantity is under 200, and then anything over 200 will be rounded to the nearest 50???
Would it make a difference if a form is involved or not? I just don't want a page refresh and would rather trigger an AJAX function that would display options beneath the quantity input - all of which would be based on the quantity input. For instance if a quantity of 12 was input, then options A, B and C would display.
As you had specified a "submit" button, I assumed there could be a form present as well as they normally go together, in that case you could refer to your inputbox by name and send it off using ajax.
The second example was to show an alternate method of retrieving the inputboxes value within the hypothetical ajax function "processForm".
If you created the inputbox using DOM methods such as document.createElement, then you could refer to the object reference that is passed to you.
It just depends on the code you have written already and how that value fits within it.
Bookmarks