...

View Full Version : focus on first element of table



nikko50
06-21-2012, 04:47 PM
I would like to place focus on the first input element of my table. I won't know the name of the field because the form is generated dynamically so I would just like to place focus on the first input element. How can I do this?

DaveyErwin
06-21-2012, 05:00 PM
<!DOCTYPE html>
<html>
<head>
<title> focus </title>
</head>
<body><div>
<table id='tbl'>
<tr>
<td><input></td>
</tr>
<tr>
<td><input></td>
</tr>
<tr>
<td><input></td>
</tr>
</table>
<div>
<script>
document.getElementById("tbl").getElementsByTagName("INPUT")[0].focus();
</script>
</body><html>

or maybe the table has no id ?
document.getElementsByTagName("TABLE")[0].getElementsByTagName("INPUT")[0].focus();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum