Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

commas in textboxes! 2

Status
Not open for further replies.

Gamera99

Programmer
May 17, 2001
59
0
0
JP
I am an experienced .NET programmer, and I make a lot of websites with financial calculations, text boxes, reports etc.
I have a particular page that has numerous textboxes for a person to type in numeric data; I validate the textboxes etc. when the data is submitted, etc.
Whenever I display such data outside of a textbox I always use formatnumber, formatcurrency, etc., depending on the type of data. If a person puts commas in the textbox, I strip them out with replace statement before I validate it.
HEre is my problem; a meddler in my company wants the textbox to always display commas like formatted statements do. So if I open the page, and textboxes are prepopulated with data, that data must use commas.
Well, that goes against all of the "best work practices" and standards that I have ever seen.
What do you people think? Have you ever done this? I want to completely ignore it and apply some technical rationale to it; we simply don't do data forms this way, etc.
Does anyone have any ideas about this?
Thank you
Nelson
 
Tally up how long it would take you to make th change then express concern over the amount your dept will have to charge his for this relatively minor and non-standard approach to numbers :)

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
This will do add commas as they type. You could modify it to loop through all elements onload to change data already there:

<html>
<head>
<script language="JavaScript">
<!--
function outputComma(number) {
var temp = number.value.replace(/[^0-9]/g, "");
temp = '' + temp
if (temp.length > 3) {
var mod = temp.length%3;
var output = (mod > 0 ? (temp.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(temp.length/3) ; i++) {
if ((mod ==0) && (i ==0))
output+= temp.substring(mod+3*i,mod+3*i+3);
else
output+= ',' + temp.substring(mod+3*i,mod+3*i+3);
}
number.value = output;
return true
}
else {
number.value = temp;
return true
}
}


--></script>
</head>
<body>
<form name=myform>
<input type="text" name="mynumber" value="" onKeyUp="return outputComma(this)">
</form>
</body>
</html>
 
Then again it wouold probably only take you about five minutes to enclose all the Response.Print values forthe inputs with FormatNumber/Currencies so you could always just go ahead and do it, shouldn't hurt if your already removing commas on your processing page (when it is submitted).

Course you could also add something odd, like a javascript routine to detect the comma an change the text to blue or something, call it an internal browsr error that people will just have to live with in order to get the commas they wat :p

I'm not a troublemaker, honest ;)

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top