PDA

Click to See Complete Forum and Search --> : Defaulting Cursor on Web Page


Mattyboy2000
Apr 3rd, 2002, 02:21 AM
I have a asp page with multiple text boxes on and want the cursor to automatically be put into any one of these when the user browses to the page.

Please can anyone help! My javascript knowledge is poo!!!

punkpie_uk
Apr 3rd, 2002, 02:41 AM
Heres a quick example...


<html>
<head>
<title>Set Focus Example</title>
</head>
<body onload="document.form1.text1.focus()">
<form name="form1">
<input type="text" name="text1">
<input type="text" name="text2">
<input type="text" name="text3">
</form>
</body>
</html>


document.form1.text1.focus() sets the default focus of a text box. It works like this...

document tells javascript to work on the current document (always have this)
form1 is the name of the form where the text boxes are situated. In my example its form1 (where it says <form name="form1">)
text1 is the name of the text box you want default focus. In my example its text1 but it could easily be text2 or text3
focus() sets focus to it

If you want this to work you have to remember to give the form and text boxes a name attribute.

Hope this helps

Mattyboy2000
Apr 3rd, 2002, 03:54 AM
That is great many thanks for a speedy reply!