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

Formatting text boxes in InterDev

Status
Not open for further replies.

JulieS

MIS
Nov 23, 2000
48
CA
I'm new to InterDev, and am pulling my hair out trying to format text boxes.

For example, when the user has to enter a phone number, i want it in the format:
(***)***-****

I want to be able to set the field like I am able to in Access. Is this possible?
 
Dear JulieS,

> I want to be able to set the field like I am able to in Access. Is this possible?

No, a web browser is NOT Microsoft Access, therefore you will not be able to do things 'like I am able to in Access'.

-pete
 
I know the feeling of frustration when you are able to do something very easily in Access but simply can not do it in Interdev. You will enjoy Interdev once you get the hang of it but it will take some getting used to.

I was never able to find an easy to implement phone number formating option. I eventually just added space to my db field and asked users to format the phone number themselves. I know this is not the most user friendly option available but it does allow for people to format the number how they want.

Keep your chin up it gets better LOL
Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
I recently was able to fomat my DTC text box that was bound to a datetime field: Here's what I did:

I placed the following code into the OnChange event of my DTC text box (txtDate).

txtDate.value=FormatDateTime(txtDate.value,2)
This formats it as follows: mm\dd\yy

The problem I'm having now is that after I use the OnChange event I loose focus of the control. Therefore, I can't continue to tab to the next control.

Is there anyway around this???

Thanks,
Anna
 
Formatting can occur in many places (server and client). And for text-boxes, the formatting may need to be removed/altered when storing back to the database. ASP.NET is much better in this area (well, most areas to be honest).

To format data going into a textbox, do this to the variable before assignment to the textbox.

When the user modifies the text, you need to use some CLIENT-SIDE javascript code.
For a hand-built INPUT box, you just add
onblur="myFormatFunction(this)"
onfocus="myUnFormatFunction(this)"

For a DTC, you need to 'advise' these events to each textbox
in the thisPage_onenter method:

txtDate.advise ("onblur", "dummy")
txtDate.advise ("onfocus", "dummy")

The "dummy" bit is meant to be the name of a Server-Side function - but we do not want it to go that far. So how do we prevent a Server Round-Trip?

Add a Client-Side code block with the following:

function thisPage_onbeforeserverevent(strObj, strEvt) {
if (strObj == "txtDate") {
if (strEvt=="onblur") {
myFormatFunction(document.thisForm.txtDate);
thisPage.cancelEvent = true
}
if (strEvt=="onfocus") {
myUnFormatFunction(document.thisForm.txtDate);
thisPage.cancelEvent = true
}
}
}
Note1: The parameters (strObj, strEvt) are not added by VisualInderdev if you double-click this event in the Script Outline View.
Note2: VisualInterdev does not pop-up the DTC textbox names - but they ARE valid. So just spell them correctly!

You could put the format / unformat functions in a separate javascript file that you include in the client page.
<script language=&quot;JavaScript&quot;
src=&quot;../include/FormatFunctions.js&quot;>
</script>
You would need similar functions on the server-side code too. You would include them as
<!--#INCLUDE FILE=&quot;../include/FormatFunctions.asp&quot;-->
(Content Management)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top