473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

dynamically modify textbox AS the user types in it?

Hi -

I am looking for a way to dynamically alter a textbox WHILE the user is
typing in it. One example would be while a user is entering their phone
number a dash would be entered automatically as soon as the user types the
third digit - the fourth digit would then follow the dash.

I've seen this done on several sites now. I know it can be done once the
user leaves the textbox with a postback, but I would like to try to
accomplish it while the user is typing.

Any help would be appreciated. I'm not sure how to go about it. I'm using C#
but VB is okay too.'

Thank you,

Jason
Nov 18 '05 #1
4 2178
You will need to use some client side javascript.
create a 'onkeypress' event, count the characters and modify accordingly.

eg
<input type='button' onkeypress='setFormat' id='myButton' >

<script language=jscript>
function setFormat(){

var obj = document.getElementById('myButton');

var len = obj.value.length;

if(len ==3)
obj.value += '-';
else
return;

}
</script>
"Jason Cowsill" <ja***@lotuseater.net> wrote in message
news:u%****************@TK2MSFTNGP11.phx.gbl...
Hi -

I am looking for a way to dynamically alter a textbox WHILE the user is
typing in it. One example would be while a user is entering their phone
number a dash would be entered automatically as soon as the user types the
third digit - the fourth digit would then follow the dash.

I've seen this done on several sites now. I know it can be done once the
user leaves the textbox with a postback, but I would like to try to
accomplish it while the user is typing.

Any help would be appreciated. I'm not sure how to go about it. I'm using C# but VB is okay too.'

Thank you,

Jason

Nov 18 '05 #2
First off, I STRONGLY urge you to reconsider use of masked imput
boxes. I know there are people who like them, but - well - I guess I
think I know what they "really" want more than they do. Masked imputs
are more of a problem than they are worth most of the time. Getting
the things to work in all cases is quite difficult, and I have never
seen one that works the way I would want it to.

The problems begin when you consider the possibility of someone
editing an existing value, pasting a value into the text box,
dynamically changing the value via code, etc etc. Also, consider the
people who do not use IE, or even turn off Javascript on their PC - or
Mac? or PocketPC, or Cell phone???? Also, in your example of a phone
number, what if the person would really like to enter it with
parentheses around the area code? What if it is an international
number with a country code? Are you going to code for all these
possibilities - and make it work while editing, pasting, deleting,
etc?

Consider adding seperate text boxes for the different parts of the
input - one for the area code, and two for the different parts of the
phone number.

In the end, I call it a balance thing. You are GOING to get some
people wanting it a different way than you code it. Most people are
more comfortable with plain text. I can validate and reformat for
output. If I appease the few, I piss off the many :)

As an asside, the most common reason I have heard for input masks is
for people coming from mainframe dumb terminal days where they did not
need to enter characters during data input. The best example I know if
where I had a hospital want to have their people put a birthday in as
6 digits - format mmddyy. I tried and tried to convince them that they
"at least" needed mmddyyyy, but they pressed back. In the end, they
had to accept the fact that some insurance claims would be rejected
because they put 050103 in as the birthdate, claiming a hip
replacement procedure. The birthdate, of course was validated as
5/1/2003 instead of 5/1/1903. Ya try to convince people you know more
than they do, and - darn it - sometimes they dont believe you! :)

Dan


On Sat, 6 Mar 2004 21:01:01 -0800, "Jason Cowsill"
<ja***@lotuseater.net> wrote:
Hi -

I am looking for a way to dynamically alter a textbox WHILE the user is
typing in it. One example would be while a user is entering their phone
number a dash would be entered automatically as soon as the user types the
third digit - the fourth digit would then follow the dash.

I've seen this done on several sites now. I know it can be done once the
user leaves the textbox with a postback, but I would like to try to
accomplish it while the user is typing.

Any help would be appreciated. I'm not sure how to go about it. I'm using C#
but VB is okay too.'

Thank you,

Jason


Nov 18 '05 #3
Try that...

http://www.eztree-msdn.com

Regards...

LJ

"Dan Brussee" <db******@nc.rr.com> a écrit dans le message de news:
bc********************************@4ax.com...
First off, I STRONGLY urge you to reconsider use of masked imput
boxes. I know there are people who like them, but - well - I guess I
think I know what they "really" want more than they do. Masked imputs
are more of a problem than they are worth most of the time. Getting
the things to work in all cases is quite difficult, and I have never
seen one that works the way I would want it to.

The problems begin when you consider the possibility of someone
editing an existing value, pasting a value into the text box,
dynamically changing the value via code, etc etc. Also, consider the
people who do not use IE, or even turn off Javascript on their PC - or
Mac? or PocketPC, or Cell phone???? Also, in your example of a phone
number, what if the person would really like to enter it with
parentheses around the area code? What if it is an international
number with a country code? Are you going to code for all these
possibilities - and make it work while editing, pasting, deleting,
etc?

Consider adding seperate text boxes for the different parts of the
input - one for the area code, and two for the different parts of the
phone number.

In the end, I call it a balance thing. You are GOING to get some
people wanting it a different way than you code it. Most people are
more comfortable with plain text. I can validate and reformat for
output. If I appease the few, I piss off the many :)

As an asside, the most common reason I have heard for input masks is
for people coming from mainframe dumb terminal days where they did not
need to enter characters during data input. The best example I know if
where I had a hospital want to have their people put a birthday in as
6 digits - format mmddyy. I tried and tried to convince them that they
"at least" needed mmddyyyy, but they pressed back. In the end, they
had to accept the fact that some insurance claims would be rejected
because they put 050103 in as the birthdate, claiming a hip
replacement procedure. The birthdate, of course was validated as
5/1/2003 instead of 5/1/1903. Ya try to convince people you know more
than they do, and - darn it - sometimes they dont believe you! :)

Dan


On Sat, 6 Mar 2004 21:01:01 -0800, "Jason Cowsill"
<ja***@lotuseater.net> wrote:
Hi -

I am looking for a way to dynamically alter a textbox WHILE the user is
typing in it. One example would be while a user is entering their phone
number a dash would be entered automatically as soon as the user types thethird digit - the fourth digit would then follow the dash.

I've seen this done on several sites now. I know it can be done once the
user leaves the textbox with a postback, but I would like to try to
accomplish it while the user is typing.

Any help would be appreciated. I'm not sure how to go about it. I'm using C#but VB is okay too.'

Thank you,

Jason

Nov 18 '05 #4
Ok, I'll bite... what about it?

On Sun, 7 Mar 2004 15:28:47 +0100, "\(Laurent Jordi\)"
<la*****@ezlogic.mc> wrote:
Try that...

http://www.eztree-msdn.com

Regards...

LJ

"Dan Brussee" <db******@nc.rr.com> a écrit dans le message de news:
bc********************************@4ax.com...
First off, I STRONGLY urge you to reconsider use of masked imput
boxes. I know there are people who like them, but - well - I guess I
think I know what they "really" want more than they do. Masked imputs
are more of a problem than they are worth most of the time. Getting
the things to work in all cases is quite difficult, and I have never
seen one that works the way I would want it to.

The problems begin when you consider the possibility of someone
editing an existing value, pasting a value into the text box,
dynamically changing the value via code, etc etc. Also, consider the
people who do not use IE, or even turn off Javascript on their PC - or
Mac? or PocketPC, or Cell phone???? Also, in your example of a phone
number, what if the person would really like to enter it with
parentheses around the area code? What if it is an international
number with a country code? Are you going to code for all these
possibilities - and make it work while editing, pasting, deleting,
etc?

Consider adding seperate text boxes for the different parts of the
input - one for the area code, and two for the different parts of the
phone number.

In the end, I call it a balance thing. You are GOING to get some
people wanting it a different way than you code it. Most people are
more comfortable with plain text. I can validate and reformat for
output. If I appease the few, I piss off the many :)

As an asside, the most common reason I have heard for input masks is
for people coming from mainframe dumb terminal days where they did not
need to enter characters during data input. The best example I know if
where I had a hospital want to have their people put a birthday in as
6 digits - format mmddyy. I tried and tried to convince them that they
"at least" needed mmddyyyy, but they pressed back. In the end, they
had to accept the fact that some insurance claims would be rejected
because they put 050103 in as the birthdate, claiming a hip
replacement procedure. The birthdate, of course was validated as
5/1/2003 instead of 5/1/1903. Ya try to convince people you know more
than they do, and - darn it - sometimes they dont believe you! :)

Dan


On Sat, 6 Mar 2004 21:01:01 -0800, "Jason Cowsill"
<ja***@lotuseater.net> wrote:
>Hi -
>
>I am looking for a way to dynamically alter a textbox WHILE the user is
>typing in it. One example would be while a user is entering their phone
>number a dash would be entered automatically as soon as the user typesthe >third digit - the fourth digit would then follow the dash.
>
>I've seen this done on several sites now. I know it can be done once the
>user leaves the textbox with a postback, but I would like to try to
>accomplish it while the user is typing.
>
>Any help would be appreciated. I'm not sure how to go about it. I'm usingC# >but VB is okay too.'
>
>Thank you,
>
>Jason
>


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: codemonkey | last post by:
TIA! I would like to know if there is a way to dynamically change the colors of Subform items? I have already set in place Conditional Formatting so each row has an alernating color scheme, but...
1
by: Tony | last post by:
Hi folks, I've got a bit of a problem. I have a situation where I build forms completely dynamically based on a form definition supplied from a database. Anyway, I noticed that required fields...
3
by: Forconi Boris via .NET 247 | last post by:
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
4
by: Joe | last post by:
I have an xml file which looks similar to this: <data> Please enter the value: <dynamicControl id="myDC", type="Textbox", MaxLength="100"/> </data> I am trying to devise a way to have a web...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
13
by: Konrad Hammerer | last post by:
Hi! Can somebody tell me or show me an example how to add a textbox and a button dynamically by code to an apsx page and how to read the filled in value from the textbox after the user has...
3
by: ton | last post by:
Hi, I'm using AJAXPRO this works very well. What I want to do is to add new page elements at my web site without using a postback. And I do not mean listitems but a complete dialog. Let me...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.