473,322 Members | 1,671 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,322 software developers and data experts.

legal character not working in textArea

So, I have a textArea that "onKeyPress= return checkLegalChar(event);" which the function checkLegalChar(event), returns false if a certain character is typed in the box.

// --------------Here is the function:---------------------------------------------------------------------

function checkLegalChar(event)
{
if ("%\"|~\\".indexOf(String.fromCharCode(event.keyCo de)) == -1) return (true);
else return (false);
}
//---------------------------------------------------------------------------------------------------------------

This function works great in a textbox, but it drops an "Object Expected" onKeyPrerss. Can anyone spot my problem? Thanks.
Jan 2 '07 #1
2 1168
b1randon
171 Expert 100+
So, I have a textArea that "onKeyPress= return checkLegalChar(event);" which the function checkLegalChar(event), returns false if a certain character is typed in the box.

// --------------Here is the function:---------------------------------------------------------------------

function checkLegalChar(event)
{
if ("%\"|~\\".indexOf(String.fromCharCode(event.keyCo de)) == -1) return (true);
else return (false);
}
//---------------------------------------------------------------------------------------------------------------

This function works great in a textbox, but it drops an "Object Expected" onKeyPrerss. Can anyone spot my problem? Thanks.
I had no problems when I used:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><script type="text/javascript" src="script.js"></script></head>
  3. <body>
  4. <textarea onKeyPress="return checkLegalChar(event);"></textarea>
  5. </body>
  6. </html>
  7.  
&
Expand|Select|Wrap|Line Numbers
  1. function checkLegalChar(event)
  2. {
  3.     if ("%\"|~\\".indexOf(String.fromCharCode(event.keyCode)) == -1) 
  4.         return (true);
  5.     else 
  6.         return (false);
  7. }
  8.  
Except for the fact that it doesn't work in FireFox at all ;( Try my code maybe?
Jan 2 '07 #2
I had no problems when I used:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><script type="text/javascript" src="script.js"></script></head>
  3. <body>
  4. <textarea onKeyPress="return checkLegalChar(event);"></textarea>
  5. </body>
  6. </html>
  7.  
&
Expand|Select|Wrap|Line Numbers
  1. function checkLegalChar(event)
  2. {
  3.     if ("%\"|~\\".indexOf(String.fromCharCode(event.keyCode)) == -1) 
  4.         return (true);
  5.     else 
  6.         return (false);
  7. }
  8.  
Except for the fact that it doesn't work in FireFox at all ;( Try my code maybe?


I forgot that the function of checkLegalChar(even) is in a separate .js file. I don't know if I'm importing correctly or not, yet the textboxes seem to use the function fine. So far, the solution is to create a separate function within the same file as were the textArea is set at and to not have the "(event)" be a parameter.

Yeah, I know. It's not compatible in FF right now. It's completely geared toward IE7 and older. :D Thanks for the notice. Good to see another FireFox fan.
Jan 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: reneecccwest | last post by:
Please discard the previous message. It should be characters instead of words. can anybody share the code for a character counter for the textarea user input? what if max characters are 256? ...
8
by: lawrence | last post by:
I'm a beginner with Javascript and especially cross-browser Javascript. I got this working in IE, but not in Netscape 7. It seems like, in Netscape, every time I click on a button, the focus shifts...
3
by: Bob Rivers | last post by:
Hi, I'm trying to build a web page where the user can insert text dinamically. When the user hits a button, a new text box is created and the user can insert text into it. It's working nice...
2
by: Thomas Paul Diffenbach | last post by:
I'm trying to write a space efficient string (nul terminated array of char), storing the characters directly unless the number of characters is too large to be so stored, and storing a pointer to...
6
by: @sh | last post by:
Guys, Working on a function to alert the user to too many characters being entered into a text area, I've put together this function so far borrowing bits from resource websites... function...
5
by: JNariss | last post by:
Hello, Within a form I created I have placed links that users can click on to view information. I am trying to write a javascript code so it opens in a sized window but I can't seem to figure...
3
by: ITAutobot25 | last post by:
Now this is really the last problem (for real now) with this assignment. My sorter is not working. I managed to sort by product name in my previous assignment; however, I can't get it to work on this...
0
by: Germaris | last post by:
Hi there! I implemented a printing function which is working nice even for multiple pages. Problem is as follows... Say we have a text 100 lines long. Each page can hold 80 lines. We should...
16
by: bgold12 | last post by:
Will newlines ever be standardized? I recently discovered that in a textarea, internet explorer adds \r\n for every newline you enter, while firefox adds \n. I know \r is also used in some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.