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!

I need to put focus on a button when a user presses enter on textbox 1

Status
Not open for further replies.

akgta

Programmer
Jul 18, 2007
42
CA
I need to put focus on a button when a user presses enter on a textbox, both components are part of one form

how is it achievable, you help is highly appreciated.
 
Here is a very quick example page that you can use to adapt to your code:

Code:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function checkForEnter(e)
{
	var l_oKeycode = '';
	if (window.event)
	{
		l_oKeycode = window.event.keyCode;
	} else {
		l_oKeycode = e.which;
	}
	if (l_oKeycode == 13)
	{
		setTimeout("document.getElementById('btn').focus()",10);
	}
}
</script>
</head>
<body>
<form action="" onsubmit="return false;">
<fieldset>
	<input type="text" name="q" id="q" value="" onkeydown="checkForEnter(event)"/>
	<button id="btn" onfocus="alert('I was focussed')">Some button</button>
</fieldset>
</form>
</body>
</html>

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top