473,544 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set Focus to html form problem

Hi,

I have a function that I call from form fields using the OnKeyUp
function to replace special caracters. Once this function has been
called, it does not set the focus on the form field where I have
called the function from.

What happens :

I laod a EDIT page with a html form on it and fill in the fields with
values from a database. Now when I use the tab button to move to next
field that contains a value, it calls the function and then the focus
is not set to the same field, so I have to click on the field with the
mouse to edit the value.

Below is a example of my form and then the function in that it calls.

Any help will be much apreciated.

HTML FORM :

<input type=text name=Street Value="<% =Server.HTMLEnc ode(rs("Street" ))
%>" size="30" onKeyUp="fix_ch ars(this);"><BR >
<input type=text name=Suburb Value="<% =Server.HTMLEnc ode(rs("Suburb" ))
%>" size="30" onKeyUp="fix_ch ars(this);"><BR >
<input type=text name=Location Value="<%
=Server.HTMLEnc ode(rs("Locatio n"))%>" size="30"
onKeyUp="fix_ch ars(this);"><BR >

JAVASCRIPT FUNCTION :

function fix_chars(textB ox)
{
textBox.value = textBox.value.r eplace(/[À]/g, "A");
textBox.value = textBox.value.r eplace(/[Á]/g, "A");
textBox.value = textBox.value.r eplace(/[Â]/g, "A");
textBox.value = textBox.value.r eplace(/[Ã]/g, "A");
textBox.value = textBox.value.r eplace(/[Ä]/g, "C");
textBox.value = textBox.value.r eplace(/[Å]/g, "C");
textBox.value = textBox.value.r eplace(/[Æ]/g, "AE");
textBox.value = textBox.value.r eplace(/[Ç]/g, "C");
textBox.value = textBox.value.r eplace(/[È]/g, "E");
textBox.value = textBox.value.r eplace(/[É]/g, "E");
textBox.value = textBox.value.r eplace(/[Ê]/g, "E");
textBox.value = textBox.value.r eplace(/[Ë]/g, "E");
textBox.value = textBox.value.r eplace(/[Ì]/g, "I");
textBox.value = textBox.value.r eplace(/[Í]/g, "I");
textBox.value = textBox.value.r eplace(/[Î]/g, "Î");
textBox.value = textBox.value.r eplace(/[Ï]/g, "I");
textBox.value = textBox.value.r eplace(/[Ð]/g, "ETH");
textBox.value = textBox.value.r eplace(/[Ñ]/g, "N");
textBox.value = textBox.value.r eplace(/[Ò]/g, "O");
textBox.value = textBox.value.r eplace(/[Ó]/g, "O");
textBox.value = textBox.value.r eplace(/[Ô]/g, "O");
textBox.value = textBox.value.r eplace(/[Õ]/g, "O");
textBox.value = textBox.value.r eplace(/[Ö]/g, "O");
textBox.value = textBox.value.r eplace(/[Ø]/g, "O");
textBox.value = textBox.value.r eplace(/[Ù]/g, "U");
textBox.value = textBox.value.r eplace(/[Ú]/g, "U");
textBox.value = textBox.value.r eplace(/[Û]/g, "U");
textBox.value = textBox.value.r eplace(/[Ü]/g, "U");
textBox.value = textBox.value.r eplace(/[Ý]/g, "Y");
textBox.value = textBox.value.r eplace(/[Þ]/g, "THORN");
textBox.value = textBox.value.r eplace(/[ß]/g, "s");
textBox.value = textBox.value.r eplace(/[*]/g, "a");
textBox.value = textBox.value.r eplace(/[á]/g, "a");
textBox.value = textBox.value.r eplace(/[â]/g, "a");
textBox.value = textBox.value.r eplace(/[ã]/g, "a");
textBox.value = textBox.value.r eplace(/[ä]/g, "a");
textBox.value = textBox.value.r eplace(/[å]/g, "a");
textBox.value = textBox.value.r eplace(/[æ]/g, "ae");
textBox.value = textBox.value.r eplace(/[ç]/g, "c");
textBox.value = textBox.value.r eplace(/[è]/g, "e");
textBox.value = textBox.value.r eplace(/[é]/g, "e");
textBox.value = textBox.value.r eplace(/[ê]/g, "e");
textBox.value = textBox.value.r eplace(/[ë]/g, "e");
textBox.value = textBox.value.r eplace(/[ì]/g, "i");
textBox.value = textBox.value.r eplace(/[*]/g, "i");
textBox.value = textBox.value.r eplace(/[î]/g, "i");
textBox.value = textBox.value.r eplace(/[ï]/g, "i");
textBox.value = textBox.value.r eplace(/[ð]/g, "eth");
textBox.value = textBox.value.r eplace(/[ñ]/g, "n");
textBox.value = textBox.value.r eplace(/[ò]/g, "o");
textBox.value = textBox.value.r eplace(/[ó]/g, "o");
textBox.value = textBox.value.r eplace(/[ô]/g, "o");
textBox.value = textBox.value.r eplace(/[õ]/g, "o");
textBox.value = textBox.value.r eplace(/[ö]/g, "o");
textBox.value = textBox.value.r eplace(/[ø]/g, "o");
textBox.value = textBox.value.r eplace(/[ù]/g, "u");
textBox.value = textBox.value.r eplace(/[ú]/g, "u");
textBox.value = textBox.value.r eplace(/[û]/g, "u");
textBox.value = textBox.value.r eplace(/[ü]/g, "u");
textBox.value = textBox.value.r eplace(/[ý]/g, "y");
textBox.value = textBox.value.r eplace(/[þ]/g, "thorn");
textBox.value = textBox.value.r eplace(/[ÿ]/g, "y");
textBox.value = textBox.value.r eplace(/[Œ]/g, "OE");
textBox.value = textBox.value.r eplace(/[œ]/g, "oe");
textBox.value = textBox.value.r eplace(/[*]/g, "S");
textBox.value = textBox.value.r eplace(/[š]/g, "s");
textBox.value = textBox.value.r eplace(/[Ÿ]/g, "Y");
}
THANKS Hugo

Mar 28 '07 #1
3 4910
hu**@oligroup.c om said the following on 3/28/2007 9:52 AM:
Hi,

I have a function that I call from form fields using the OnKeyUp
function to replace special caracters.
Having a page change my text as I type would be irritating at the least.
Use the onchange event instead.
Once this function has been called, it does not set the focus
on the form field where I have called the function from.

Set a global variable and every time a field gains focus, set that
variable to the fields name. Then at the end of your function set focus
back where you wanted it.

onfocus="thisFi eld=this.name;"
var thisField="";

function fix_chars(textB ox)
{
<snip>

document.forms['formID'].elements[thisField].focus();

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 28 '07 #2
On 28 Mar, 16:57, Randy Webb <HikksNotAtH... @aol.comwrote:
h...@oligroup.c om said the following on 3/28/2007 9:52 AM:
Hi,
I have a function that I call from form fields using the OnKeyUp
function to replace special caracters.

Having a page change my text as I type would be irritating at the least.
Use the onchange event instead.
Once this function has been called, it does not set the focus
on the form field where I have called the function from.

Set a global variable and every time a field gains focus, set that
variable to the fields name. Then at the end of your function set focus
back where you wanted it.

onfocus="thisFi eld=this.name;"

var thisField="";
function fix_chars(textB ox)
{

<snip>

document.forms['formID'].elements[thisField].focus();

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/
Thanks for your help dude !

I have tried the following but get an error.
I have changed ['formID'] to ['myform'] because my form name is
"myform" Is this correct ?

Any more help ?

<script language="javas cript">
<!--

onfocus="thisFi eld=this.name;"
var thisField="";
function fix_chars(textB ox)
{

textBox.value = textBox.value.r eplace(/[À]/g, "A");
textBox.value = textBox.value.r eplace(/[Á]/g, "A");
textBox.value = textBox.value.r eplace(/[Â]/g, "A");
textBox.value = textBox.value.r eplace(/[Ã]/g, "A");
textBox.value = textBox.value.r eplace(/[Ä]/g, "C");
textBox.value = textBox.value.r eplace(/[Å]/g, "C");
textBox.value = textBox.value.r eplace(/[Æ]/g, "AE");
textBox.value = textBox.value.r eplace(/[Ç]/g, "C");
textBox.value = textBox.value.r eplace(/[È]/g, "E");
textBox.value = textBox.value.r eplace(/[É]/g, "E");
textBox.value = textBox.value.r eplace(/[Ê]/g, "E");
textBox.value = textBox.value.r eplace(/[Ë]/g, "E");
textBox.value = textBox.value.r eplace(/[Ì]/g, "I");
textBox.value = textBox.value.r eplace(/[Í]/g, "I");
textBox.value = textBox.value.r eplace(/[Î]/g, "Î");
textBox.value = textBox.value.r eplace(/[Ï]/g, "I");
textBox.value = textBox.value.r eplace(/[Ð]/g, "ETH");
textBox.value = textBox.value.r eplace(/[Ñ]/g, "N");
textBox.value = textBox.value.r eplace(/[Ò]/g, "O");
textBox.value = textBox.value.r eplace(/[Ó]/g, "O");
textBox.value = textBox.value.r eplace(/[Ô]/g, "O");
textBox.value = textBox.value.r eplace(/[Õ]/g, "O");
textBox.value = textBox.value.r eplace(/[Ö]/g, "O");
textBox.value = textBox.value.r eplace(/[Ø]/g, "O");
textBox.value = textBox.value.r eplace(/[Ù]/g, "U");
textBox.value = textBox.value.r eplace(/[Ú]/g, "U");
textBox.value = textBox.value.r eplace(/[Û]/g, "U");
textBox.value = textBox.value.r eplace(/[Ü]/g, "U");
textBox.value = textBox.value.r eplace(/[Ý]/g, "Y");
textBox.value = textBox.value.r eplace(/[Þ]/g, "THORN");
textBox.value = textBox.value.r eplace(/[ß]/g, "s");
textBox.value = textBox.value.r eplace(/[*]/g, "a");
textBox.value = textBox.value.r eplace(/[á]/g, "a");
textBox.value = textBox.value.r eplace(/[â]/g, "a");
textBox.value = textBox.value.r eplace(/[ã]/g, "a");
textBox.value = textBox.value.r eplace(/[ä]/g, "a");
textBox.value = textBox.value.r eplace(/[å]/g, "a");
textBox.value = textBox.value.r eplace(/[æ]/g, "ae");
textBox.value = textBox.value.r eplace(/[ç]/g, "c");
textBox.value = textBox.value.r eplace(/[è]/g, "e");
textBox.value = textBox.value.r eplace(/[é]/g, "e");
textBox.value = textBox.value.r eplace(/[ê]/g, "e");
textBox.value = textBox.value.r eplace(/[ë]/g, "e");
textBox.value = textBox.value.r eplace(/[ì]/g, "i");
textBox.value = textBox.value.r eplace(/[*]/g, "i");
textBox.value = textBox.value.r eplace(/[î]/g, "i");
textBox.value = textBox.value.r eplace(/[ï]/g, "i");
textBox.value = textBox.value.r eplace(/[ð]/g, "eth");
textBox.value = textBox.value.r eplace(/[ñ]/g, "n");
textBox.value = textBox.value.r eplace(/[ò]/g, "o");
textBox.value = textBox.value.r eplace(/[ó]/g, "o");
textBox.value = textBox.value.r eplace(/[ô]/g, "o");
textBox.value = textBox.value.r eplace(/[õ]/g, "o");
textBox.value = textBox.value.r eplace(/[ö]/g, "o");
textBox.value = textBox.value.r eplace(/[ø]/g, "o");
textBox.value = textBox.value.r eplace(/[ù]/g, "u");
textBox.value = textBox.value.r eplace(/[ú]/g, "u");
textBox.value = textBox.value.r eplace(/[û]/g, "u");
textBox.value = textBox.value.r eplace(/[ü]/g, "u");
textBox.value = textBox.value.r eplace(/[ý]/g, "y");
textBox.value = textBox.value.r eplace(/[þ]/g, "thorn");
textBox.value = textBox.value.r eplace(/[ÿ]/g, "y");
textBox.value = textBox.value.r eplace(/[Œ]/g, "OE");
textBox.value = textBox.value.r eplace(/[œ]/g, "oe");
textBox.value = textBox.value.r eplace(/[*]/g, "S");
textBox.value = textBox.value.r eplace(/[š]/g, "s");
textBox.value = textBox.value.r eplace(/[Ÿ]/g, "Y");

document.forms['myform'].elements[thisField].focus();

}
-->
</script>

Mar 29 '07 #3
hu**@oligroup.c om said the following on 3/29/2007 5:53 AM:
On 28 Mar, 16:57, Randy Webb <HikksNotAtH... @aol.comwrote:
>h...@oligroup. com said the following on 3/28/2007 9:52 AM:
<snip>
I have tried the following but get an error.
I have changed ['formID'] to ['myform'] because my form name is
"myform" Is this correct ?
Yes.
Any more help ?

<script language="javas cript">
<!--

onfocus="thisFi eld=this.name;"
var thisField="";
The onfocus line goes in your HTML element, not in the script block.
Remove the line above that starts onfocus. Then, make your input
elements look something like this:

<input type=text name=Street Value="somethin g" size="30"
onKeyUp="fix_ch ars(this);" onfocus="thisFi eld=this.name"> <BR>

And add it to every input in the page.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 29 '07 #4

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

Similar topics

11
4456
by: JCO | last post by:
I have a text box, on my form that I cant get the focus on. I'm using it as shown: <head> <body onload=document.getPassword.txtPasswordName.focus()> </head> Where getPassword is the form & txtPasswordName is the text box
4
2383
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML> <HEAD> </HEAD> <BODY> <FORM>
2
6712
by: Iver Erling rva | last post by:
I have this window where I open a modal dialog window using the code: newwin=window.showModalDialog(url, "popup", features) where features are dialogLeft:"+x+"px;dialogTop:"+y+"px;dialogWidth:"+w+"px;dialogHeight:"+h+"p x;center:0"
1
2226
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect page to Aspx2 which has a Datagrid. PageLoad of Aspx2 displays the DataGrid with existing data filled in and shows a new row (set of text boxes) in...
12
4870
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function cmdButton1_Clicked() { document.all('txtInput1').focus(); return false; }
4
2721
by: Johannes Kiehl | last post by:
Hi group, I've been losing most of my remaining hair today, trying to track down a problem with IE6.0 (builds: .2600 and XP SP 2). I set the border-width of form input fields to 1px via inline CSS. But whenever I call the focus() method of any of the form fields, the border width of the (first) submit button changes to 2px. It doesn't...
3
3968
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing...
1
2088
by: danyeungw | last post by:
I get the following from the link http://support.microsoft.com/kb/314206. I need to have both work - the page stays where it is and set focus to next control. Does anyone have solution? I have been working on this for days. I am using ASP.NET 2003. Thanks. DanYeung PRB: Controls Lose Focus When You Enable SmartNavigation and...
11
5331
by: karen987 | last post by:
I have a web page which used to work fine until i added a rich text editor. the pages are in ASP and it is a news weblog, with a comments section where people click the headline of a comment and it opens into a pop up page ccalled "comment_view.asp" which has a reply button. If anyone wants to reply to the message, they click reply and it...
2
2464
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. http://www.littleworksstudio.com/temp/usenet/focus.html To simulate the problem, just enter or change the "first" textbox and either click or tab to another control., it is tied to the...
0
7437
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, well explore What is ONU, What Is Router, ONU & Routers main...
0
7373
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...
0
7625
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. ...
0
7781
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...
0
7717
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...
0
5928
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5306
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...
0
3427
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
993
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.