hi folks, i needed a text input so the user that will register a product, will make sure to enter the cents, and not just the raw money, making it to be stored incorrectly on my database.
for example, if i type "1" the output inside the text field will be automatically "0.01", so the user HAS to type the cents.
thanks in advance
cents in text input
Moderator: General Moderators
Re: cents in text input
If ($x > 1) {
$x = $x * .01;
}
Is that what you need?
$x = $x * .01;
}
Is that what you need?
Re: cents in text input
sort of... but i need to display it in real time inside a text field, you know?
im a php guy, not too much into JS, so idk how exactly to make it work, and display a dot automatically on the field and stuff
but your thing sounds like the right way, just needs some developing
im a php guy, not too much into JS, so idk how exactly to make it work, and display a dot automatically on the field and stuff
but your thing sounds like the right way, just needs some developing
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: cents in text input
Code: Select all
number_format($input, 2); Re: cents in text input
Javascript would be the way to go, I've just been learning it myself recently.
I can't guarantee this will work, but give it a shot.
Just change 'input' to whatever the id of the text box is that you want to change.
There's probably a more efficient way to to that, but oh well... I'm new to js too.
Try this:
I can't guarantee this will work, but give it a shot.
Just change 'input' to whatever the id of the text box is that you want to change.
There's probably a more efficient way to to that, but oh well... I'm new to js too.
Try this:
Code: Select all
<html>
<head>
<script type='text/javascript'>
function calc() {
var num = document.getElementById('input').value
If(num > 1) {
var result = num * .01
document.getElementById('input').value=result
}
}
</script>
</head>
<body>
<input type = button name = "button" onclick = "document.getElementById('input').value=calc()value = 'Click 2'>
Re: cents in text input
This is in fact an interesting challenge. My take: http://jsfiddle.net/V9XnF/
Re: cents in text input
I'm not quite sure what I'm supposed to do with that Weirdan.
Re: cents in text input
Very niceWeirdan wrote:This is in fact an interesting challenge. My take: http://jsfiddle.net/V9XnF/
It doesn't work with Opera 10.60 for me - I can't enter any input (but Tab is working)
There are 10 types of people in this world, those who understand binary and those who don't