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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set focus to element in onchange ?

Status
Not open for further replies.

tester321

Programmer
Mar 13, 2007
150
CA
Hi is it possible (browser compatible as well) to set focus to a form element in its onchange event?

this doesn't work: this.focus()

Thanks
 
<html>
<script language=javascript>
function change(obj) {
var x;
x = obj.options[obj.selectedIndex].value;
if (x=="one") { document.forms[0].one.focus(); }
if (x=="two") { document.forms[0].two.focus(); }
if (x=="three") { document.forms[0].three.focus(); }

}
</script>
<form>
<select name=dropdown onChange="change(this.form.dropdown);">
<option SELECTED>select</option>
<option value=one>one</option>
<option value=two>two</option>
<option value=three>three</option>
</select>
<br><br>
one:&nbsp;<input name=one type=text>
<br><br>
two:&nbsp;<input name=two type=text>
<br><br>
three:&nbsp;<input name=three type=text>
</form>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top