Forum Moderators: coopster
thank you in advance.
[edited by: ergophobe at 1:00 am (utc) on Oct. 11, 2004]
[edit reason] unecessary code dump snipped as per forum charter [/edit]
This is my input box. This is where the user will input the number. all the functions are working. and i would like to add that the input should only be in 2 decimal places when it is submitted to the database while the excess decimal places will be ignored.
i will be waiting for your response.
If you don't understand Birdman's answer, you can also look at the function round [be2.php.net].
<label for="work_hours">Work Hours</label>
<input id="work_hours" name="work_hours" type="text" size="5" value= "<?php echo number_format(round($_POST['work_hours'],2),2) ;?>" onkeypress = "return onkeypressWrkHrsCheck()" onkeyup = "return onkeyupWrkHrsCheck()" onchange="update1()">
after pressing the submit button. input box displays the number i've just input (but with 2 decimal places only) which I don't want to happen. what i would like to do is after pressing the submit button the input box will display "0.00". and also when i check my database the number i've tried to input with 3 decimal places are not changed into 2 decimal places. i don't know what to do anymore. i'm stuck with this problem for 2 days. i really need help.:confused:
In the PHP script that the form submits to, put the function(Money()) in it. Then, when you add to the database, use the function.
Example:
$work_hrs = Money($_POST['work_hours']);
Now $work_hrs only has two digits after the decimal.
Birdman
Ps: Here are a couple JavaScript functions as well.
function formatAsMoney(mnt) {
mnt -= 0;
mnt = (Math.round(mnt*100))/100;
return (mnt == Math.floor(mnt))? mnt + '.00'
: ( (mnt*10 == Math.floor(mnt*10))?
mnt + '0' : mnt);
}
function numOnly(val,el){
if (isNaN(val)){
alert("Only numbers in this field please.");
document.forms[0].elements[el].value = "";
return;
}
}