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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Text Field

Status
Not open for further replies.

chlebicki

Technical User
Jul 4, 2006
31
US
Hi,

I am trying to format a date time text field. Right now the customer chooses a date and time from a pop-up calendar, who's value is then inserted into a text field, example: 07/17/2006 03:36:08

I am trying to format that time so if can be used as a filename but retain the date/time. So I am thinking something like 07-17-2006 03-36-08

I have been looking for a javascript that would automatically convert the text before the form is submitting, do you think this is the best way?

Thanks,
Craig
 
i would do it on the server side with coldfusion, after checking it for correctness, and i would format it like 2006-07-17-03-36-08


r937.com | rudy.ca
 
Well, I kind of found what I wanted but not exactly. I found a javascript that replaces a character via the 'onblur' function. It works when I want to replace "A" for "B", but when I want to replace "/" with "-" it doesn't work. Anyone have an idea on a work-around...here is the code:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function replaceChars(entry) {
out = "a"; // replace this
add = "z"; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.subform.text.value = temp;
}
// End -->
</script>


Any ideas?

Thanks,
Craig
 
r937,

I agree with you on that format, but how do you go from what I have to the format you recommend? Is there a tag in coldfusion that changes format?

Thanks,
Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top