473,473 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replace a character in an input box - onkeypress - FF problem

3 New Member
Hi,
I have the following code which works fine in IE but does not in Firefox:
Expand|Select|Wrap|Line Numbers
  1. <html> <head>
  2.      <title>space-plus</title>
  3. <script type="text/javascript">
  4. <!--
  5. function alpha(e) {
  6.      if(e.keyCode==32) {return (e.keyCode=43);}
  7. }
  8. // -->
  9. </script>
  10. </head>  <body> <form>
  11. <input type="text" onkeypress="return alpha(event);">
  12. </form> </body> </html>
I have tried a number of variations - without success. The idea is that when a user enters a space in the input box a plus sign is shown.
Any answers? Can Firefox do this?
May 13 '07 #1
6 22293
iam_clint
1,208 Recognized Expert Top Contributor
i believe in firefox its charCode
so you could do something like
Expand|Select|Wrap|Line Numbers
  1. <html> <head>
  2. <title>space-plus</title>
  3. <script type="text/javascript">
  4. <!--
  5. function alpha(e) {
  6. var unicode = e.charCode ? e.charCode : e.keyCode;
  7. if (unicode==32) { return (e.charCode ? e.charCode=43 : e.keyCode=43); }
  8. }
  9. // -->
  10. </script>
  11. </head> <body> <form>
  12. <input type="text" onkeypress="return alpha(event);">
  13. </form> </body> </html>
  14.  
May 13 '07 #2
tonySAN
3 New Member
Thanks Clint,
works in IE but still not in Firefox!
I wonder if the problem lies in intercepting the keycode and sending on the new keycode (or charcode). I have also tried 'onkeyup' and 'onkeydown' but these stop the function working in IE.
Your code suggestion was:
Expand|Select|Wrap|Line Numbers
  1. <html> <head>
  2. <title>space-plus</title>
  3. <script type="text/javascript">
  4. <!--
  5. function alpha(e) {
  6. var unicode = e.charCode ? e.charCode : e.keyCode;
  7. if (unicode==32) { return (e.charCode ? e.charCode=43 : e.keyCode=43); }
  8. }
  9. // -->
  10. </script>
  11. </head> <body> <form>
  12. <input type="text" onkeypress="return alpha(event);">
  13. </form> </body> </html>
May 13 '07 #3
Logician
210 New Member
The idea is that when a user enters a space in the input box a plus sign is shown.
Any answers? Can Firefox do this?
<input type='text' onkeyup="this.value=this.value.replace(/\s/g,'+')">
May 13 '07 #4
tonySAN
3 New Member
Thank you Logician. Does the job! (In both browsers.)
TS.
May 14 '07 #5
chetannagar
1 New Member
i believe in firefox its charCode
so you could do something like
Expand|Select|Wrap|Line Numbers
  1. <html> <head>
  2. <title>space-plus</title>
  3. <script type="text/javascript">
  4. <!--
  5. function alpha(e) {
  6. var unicode = e.charCode ? e.charCode : e.keyCode;
  7. if (unicode==32) { return (e.charCode ? e.charCode=43 : e.keyCode=43); }
  8. }
  9. // -->
  10. </script>
  11. </head> <body> <form>
  12. <input type="text" onkeypress="return alpha(event);">
  13. </form> </body> </html>
  14.  
This code help me a lot for creating unicode in textbox.

Chetan
Feb 13 '08 #6
kul1010
1 New Member
<input type='text' onkeyup="this.value=this.value.replace(/\s/g,'+')">


very easy and good. Thank you Logician.
Jan 19 '13 #7

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

Similar topics

0
by: Nic | last post by:
How can I get character by character input without the user pressing the enter key after each single character entry?
1
by: Barb | last post by:
I'm simulating keyboard input in Visual C++ using the SendInput function. It seems to work fine for all characters (A-Z, 0-9). I am however having real problems trying to read other characters such...
2
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual...
1
by: Simon Wigzell | last post by:
I have a simple function whose purpose is to return false onkeypress and then that character should not appear in the text field. On any browser I have tried on a PC the return false means that the...
6
by: Peter.Laganis | last post by:
Hi to all, I apologize in advance if a similar question was already posted, but I didn't find it. Here is my problem: I would like to replace all the special characters ' ¾' with another...
4
by: Tim Kelley | last post by:
I am reading a text file with a streamreader. I parse out path and need to use that path in a sql statement. The path is in the file as \\servername\share\folder\filename.txt. When the line is...
33
by: cesco | last post by:
Hi, say I have a string like the following: s1 = 'hi_cat_bye_dog' and I want to replace the even '_' with ':' and the odd '_' with ',' so that I get a new string like the following: s2 =...
14
by: Ioannis Vranos | last post by:
The following code does not work as expected: #include <wchar.h> #include <locale.h> #include <stdio.h> #include <stddef.h> int main() {
4
by: Jules | last post by:
I am trying to understand the behavior of a short program. Hopefully someone can tell me what's going on. The program I wrote is: #include <stdio.h> main() { char c; while(1)
5
by: shapper | last post by:
Hello, I have a text as follows: "My email is something@something.xyz and I posted this @ 2 am" I need to replace the @ by (AT) bu only the ones that are in email addresses. All other @...
0
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,...
0
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,...
0
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...
1
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
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,...
1
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.