breeze351
asked on
Input type number not showing decimal values.
I have an input field defined as numeric. I'm trying to get it to show the decimal places. Here's the code:
if ($ROW['RENT'] == "0")
{
if ($ROW['TOTAL'] == "0")
{
$work = "0";
}
else
{
$work = ("$ROW[ANNUAL]" / "$ROW[TOTAL]");
}
}
else
{
$work = number_format("$ROW[RENT]" );
}
$work = number_format($work, 2, '.', '');
echo '<td align = "right">';
echo '<input type="number" name="$PSF" size = "9" value="';
echo $work;
echo '" maxlenghth="9" step = "0.01">';
echo '</td>';
What am I missing?
Thanks
if ($ROW['RENT'] == "0")
{
if ($ROW['TOTAL'] == "0")
{
$work = "0";
}
else
{
$work = ("$ROW[ANNUAL]" / "$ROW[TOTAL]");
}
}
else
{
$work = number_format("$ROW[RENT]"
}
$work = number_format($work, 2, '.', '');
echo '<td align = "right">';
echo '<input type="number" name="$PSF" size = "9" value="';
echo $work;
echo '" maxlenghth="9" step = "0.01">';
echo '</td>';
What am I missing?
Thanks
"$PSF" is not a 'legal' name. As told in this document http://www.w3.org/TR/1999/REC-html401-19991224/types.html#type-cdata
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").Also note that any 'id's used in javascript are case sensitive.
ASKER
No joy!
I modifed the input statement to read:
echo '<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="';
echo $work;
echo '" maxlenghth="7" step = "0.01">';
The value of $ROW[RENT] for this record is 750.00
Viewing the source in FireFox shows:
<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="750.00" maxlenghth="7" step = "0.01">
The display still shows "750". If i increment it does change to "750.01".
Any ideas?
I modifed the input statement to read:
echo '<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="';
echo $work;
echo '" maxlenghth="7" step = "0.01">';
The value of $ROW[RENT] for this record is 750.00
Viewing the source in FireFox shows:
<input type="number" name="PSF" size = "7" min = "0.00" max = "9999.99" value="750.00" maxlenghth="7" step = "0.01">
The display still shows "750". If i increment it does change to "750.01".
Any ideas?
In most languages, leading zeros and all zeros after the decimal point are discarded because they are meaningless. If you want the value of '750.00' to show you will probably have to use type="text" and not number. If you change it to '750.10', it will probably show as '750.1'.
ASKER
If I change the input type to "text", I would be hoping that the user doesn't enter "ABCDEF".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've done some searching around and it appears that using "text" I need to add a "pattern" to the input statement. I've tried a couple of different patterns with varying results but they created other problems.
I'm going to post the same question to HTML and see what they suggest.
Thanks
Glenn
I'm going to post the same question to HTML and see what they suggest.
Thanks
Glenn
Open in new window