Rune Runnestø wrote:
How do I focus the cursor in the input field 'numberField' when accessing
this jsp-file (or html-file) ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="numberField" size="30" >
<p><input type="submit" name="buttonAddNumber" value="Add a number">
<input type="submit" name="buttonRemoveNumber" value="Remove a number">
</form>
</body></html>
<body onload="
if(document.forms[0].elements['numberField'].focus)
document.forms[0].elements['numberField'].focus();
">
If you give your form a name, then you can substitute that for the
'0' in forms[0] and your script will not be dependent on the field
being in the first form.
e.g. if your form is called "formA", then:
<body onload="
if(document.forms['formA'].elements['numberField'].focus)
document.forms['formA'].elements['numberField'].focus();
">
....
<form action="" method="post" name="formA">
....
--
Rob