469,330 Members | 1,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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.HTMLEncode(rs("Street"))
%>" size="30" onKeyUp="fix_chars(this);"><BR>
<input type=text name=Suburb Value="<% =Server.HTMLEncode(rs("Suburb"))
%>" size="30" onKeyUp="fix_chars(this);"><BR>
<input type=text name=Location Value="<%
=Server.HTMLEncode(rs("Location"))%>" size="30"
onKeyUp="fix_chars(this);"><BR>

JAVASCRIPT FUNCTION :

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

Mar 28 '07 #1
3 4704
hu**@oligroup.com 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="thisField=this.name;"
var thisField="";

function fix_chars(textBox)
{
<snip>

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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript 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.com 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="thisField=this.name;"

var thisField="";
function fix_chars(textBox)
{

<snip>

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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.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="javascript">
<!--

onfocus="thisField=this.name;"
var thisField="";
function fix_chars(textBox)
{

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

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

}
-->
</script>

Mar 29 '07 #3
hu**@oligroup.com 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="javascript">
<!--

onfocus="thisField=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="something" size="30"
onKeyUp="fix_chars(this);" onfocus="thisField=this.name"><BR>

And add it to every input in the page.

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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by JCO | last post: by
2 posts views Thread by Iver Erling rva | last post: by
1 post views Thread by avnrao | last post: by
12 posts views Thread by CLEAR-RCIC | last post: by
4 posts views Thread by Johannes Kiehl | last post: by
2 posts views Thread by Jonathan N. Little | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.