John Doe
John Doe

Reputation: 2060

Javascript Form

I have a quick question. I am learning how to make a registration form using javascript and found this link very helpful.

http://www.w3resource.com/javascript/form/javascript-sample-registration-form-validation.php

I understand everything in the code except for this line in the html page...

<body onload="document.registration.userid.focus();">

I know it is saying that when the page is loaded run this javascript function, but I don't understand what each part does. If someone could please explain this to me I would greatly appreciate it.

Upvotes: 1

Views: 1400

Answers (2)

Evan Davis
Evan Davis

Reputation: 36592

This is the direct way to "walk the DOM." Starting from the top (document) you then select successive elements by name. The form's name is registration and the element's name is userid. The call to .focus() places the cursor in that field so that the user can begin typing immediately when the page loads instead of manually highlighting the field.

Upvotes: 1

PraveenVenu
PraveenVenu

Reputation: 8337

This means when the page is loaded set the focus on to the userid field in the form names registration in the document

You can use

document.getElementById("userid").focus()

This asks to select the field named userid in the document. So we can make it free of Form name

Upvotes: 1

Related Questions