473,883 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing Keystrokes that are not permitted within a TextArea

@sh
Has anyone a function handy that I can apply to various textboxes within a
form, each textbox will permit most characters but I want to ban certain
characters from each textbox.

Therefore I need a function that I can put into the <text area> tag of each
box, something like...

<text area onKeyPress="Ban Characters('a', '<','>','b','u' ,'i');">

Is this possible easily?

Cheers!
Dec 20 '05 #1
14 1794
@sh said the following on 12/20/2005 6:41 AM:
Has anyone a function handy that I can apply to various textboxes within a
form, each textbox will permit most characters but I want to ban certain
characters from each textbox.

Therefore I need a function that I can put into the <text area> tag of each
box, something like...

<text area onKeyPress="Ban Characters('a', '<','>','b','u' ,'i');">


<textarea onkeypress="ban Characters(this ,'character list here');
name="myTextAre a1">

Then banCharacters could check the keystrokes and compare against the
list. If its in the list, return false.

Might be better to have an array or simple object for each textarea
predefined so that you don't have to worry about syntax or arguments
list length.

Even simpler/better would be an array/object that had a list of all of
them. Something like this:

var myList = new Object();
myList['myTextArea1'] = ['a','<','>','b' ,'u','i']
myList['myTextArea2'] = ['<','>','b','u' ,'i']
and so on.

function banCharacters(t extAreaRef){
//myList[textAreaRef.nam e] will give you a reference to the list.
//loop through that list and compare to the keypress.
//return false if it matches
}

There is more work to it than that, but the approach is there. Write
your best try at it and post it back here.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '05 #2
@sh
> There is more work to it than that, but the approach is there. Write your
best try at it and post it back here.


Thanks Randy, I'll give it a go ;o) I've got to finish the application
first so I'll get there, then go back and cleanup with the Javascript
verification bits like this.

Cheers,
Dec 20 '05 #3
Randy Webb <Hi************ @aol.com> wrote:
var myList = new Object();
myList['myTextArea1'] = ['a','<','>','b' ,'u','i']
myList['myTextArea2'] = ['<','>','b','u' ,'i']


Is that somehow superior to

myList[ 'myTextArea1' ]='a<>bui';
myList[ 'myTextArea2' ]='a<>bui';

?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 20 '05 #4
Christopher Benson-Manica said the following on 12/20/2005 3:15 PM:
Randy Webb <Hi************ @aol.com> wrote:

var myList = new Object();
myList['myTextArea1'] = ['a','<','>','b' ,'u','i']
myList['myTextArea2'] = ['<','>','b','u' ,'i']

Is that somehow superior to

myList[ 'myTextArea1' ]='a<>bui';
myList[ 'myTextArea2' ]='a<>bui';


In the sense that you would have to split and then loop through the
array whereas the first is already an array.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '05 #5
Randy Webb <Hi************ @aol.com> wrote:
In the sense that you would have to split and then loop through the
array whereas the first is already an array.


I was thinking charAt(), obviating the need to split() first.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 21 '05 #6
Christopher Benson-Manica said the following on 12/20/2005 9:36 PM:
Randy Webb <Hi************ @aol.com> wrote:

In the sense that you would have to split and then loop through the
array whereas the first is already an array.

I was thinking charAt(), obviating the need to split() first.


Might be worth testing to see if using charAt is faster than the array
method. Off the top of my head, the array method should be faster.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '05 #7
Randy Webb <Hi************ @aol.com> wrote:
Might be worth testing to see if using charAt is faster than the array
method. Off the top of my head, the array method should be faster.


You're probably right, although the string method is a little cleaner
IMHO. I doubt the performance difference would be noticable for most
applications.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 21 '05 #8
On 2005-12-21, Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
Randy Webb <Hi************ @aol.com> wrote:

In the sense that you would have to split and then loop through the
array whereas the first is already an array.


I was thinking charAt(), obviating the need to split() first.


Mozilla allows somestring[index] as another way of expressing
somestring.char At(index). I don't know if that's standard or not,
it's just something I've noticed.

I haven't investigated the ways in which strings differ from arrays.

Bye.
Jasen
Dec 21 '05 #9
Jasen Betts said the following on 12/21/2005 2:16 PM:
On 2005-12-21, Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
Randy Webb <Hi************ @aol.com> wrote:

In the sense that you would have to split and then loop through the
array whereas the first is already an array.


I was thinking charAt(), obviating the need to split() first.

Mozilla allows somestring[index] as another way of expressing
somestring.char At(index).


Opera nor IE follow that construct. I remember seeing that a while back
and never bothered with it because of lack of support in other browsers.
I don't know if that's standard or not, it's just something I've noticed.
"Standard" as in ECMA Standards, or, standard as in standard behavior?

The first is irrelevant, the second is no.
I haven't investigated the ways in which strings differ from arrays.


The difference in Strings and Arrays is very significant.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '05 #10

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

Similar topics

5
2463
by: Bilal | last post by:
Hi, Is there any way to capture the action Ctrl+N (whether it in a hidden button or keyword - doesn't matter) in html, javascript or php? I appreciate any suggestions. Thank you and kind regards Bils
3
10571
by: coolsti | last post by:
Can someone help me enhance this code snippet which works only for IE so that it will also work for Firefox? I have been trying all sorts of things and have gotten to where I can capture the keydown and keypress events in Firefox, but then I can't seem to get the key code. I also don't know if the window.event.srcElement.type works with Firefox or if the onkeydown="return false" is valid in Firefox. I have this Javascript at the end of...
33
5675
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if p.pattern.groups > 100: raise AssertionError( "sorry, but this version only supports 100 named groups"
1
2585
by: Pjotr Wedersteers | last post by:
Hi I want to write a small prog/applet that does nothing but the following: Display icons representing the keys pressed on the keyboard in a small "always on top" but transparent window. The keys must always be read - even when the proggy has no focus- but not erased from the keyboard buffer so the active app still catches them. I don't want you to do the work for me, but some good pointers or tips would be very nice! I am a novice+...
1
1508
by: Rob T | last post by:
In the past, I've made several poor attempts at capturing keyboard strokes with JS. Mostly, I would want to hit something like ALT-H or F1 for a help screen.... Hitting the Alt key usually kicks you into the IE menu and doesn't really allow me to trap the keystrokes. So....on our new Exchange 2003 web interface, MS has a great interface with it. It allows you to hit ALT-S for send, F7 for spell check, and other strokes that a...
2
2287
by: jbigham | last post by:
Hello, I'd like to capture key events using javascript, but don't want to process such events when the user is typing into an input box or into a textarea. As an example, gmail has a feature where you can type "r" anywhere on the page while viewing a message and it will open a reply box, but if you type an "r" while entering text into a form, it doesn't do this. My question is how to do this most efficiently.
2
10103
by: David McDivitt | last post by:
Another fellow here must modify an application. On the web page, pressing the enter key causes the form to submit. What users want is to remove enter key functionality from within a textarea and cause the enter key to submit the form, AND cause the F6 key to do what the enter key used to do inside the text area. The idea I suggested is to trap keystrokes in the text area, If the enter key is pressed, do the submit method. If F6 is pressed,...
5
2537
by: konryd | last post by:
I want to know when a user scrolls the textarea. Since there is no such an event, I need to scroll all the ways scrolling might be invoked, that is: * by pressing keys * by moving mouse * by drag'n'dropping the scroll bar First two are easy to implement, but the third one doesn't trigger even document.onmousedown I investigated on firefox and safari under osx.
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9798
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10767
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10422
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9588
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6008
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.