Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set focus on event 1

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
Hi, Most of what I read about setting the focus of a field is on the load event. I'm trying to set the focus after a an event on the form. This event is firing (the other parts of the script work. But the .focus() doesn't seem to fire.

Any suggestions? Or is this just not an option?
Code:
window.onload=activateFxFunction;

//the following function does the work: creates the string to be placed into the label field and sets up the fields
	function setfields(){
	var currname=document.getElementById('curr').value;
	if (currname != "USD"){
			document.getElementById("foreignlbl").innerHTML = "Foreign Amount";
			document.getElementById("fxlbl").innerHTML = "Exchange Rate";

		document.getElementById("amtUS").type="text";
		document.getElementById("amtForeign").type="text";
		document.getElementById("fxRate").innerHTML= fxRate;
		document.getElementById("amtForeign").focus();
			}
	}
//this function calls the other on the changing of currency
function activateFxFunction(){
	document.getElementById("curr").onchange=setfields;
}
 
i'm guessing this works in some browsers, but not all? the thing is, a change is detected when a certain field loses focus, which could consequently mean another field is gaining focus. i've had problems properly setting focus cross-browser this way, and have attempted workarounds in the past.

you can get around this using a setTimeout method. Try something like this:

Code:
setTimeout('document.getElementById("amtForeign").focus()', 100);



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
works beautifully! Thank you CL! btw, I'm testing in Firefox 2.0

-s
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top