This week's book giveaway is in the Testing forum.
We're giving away four copies of Practical Unit Testing with TestNG and Mockito and have Tomek Kaczanowski on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes var f=document..loginForm;  how can it work? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "var f=document..loginForm;  how can it work?" Watch "var f=document..loginForm;  how can it work?" New topic
Author

var f=document..loginForm; how can it work?

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 181
I found this code in a JSP page. I don't have javascript experience and don't have a book, and I'm wondering how
var f=document.loginForm;
can work. I mean, there seems to be no reference to document or loginForm anywhere. So how can the expression document.loginForm be assigned to the f variable?

function doSubmit()
{
if (submitted)
return(false);
var f=document.loginForm;

if (f.username.value=="")
{
alert("You must enter an e-mail address.");
f.username.focus();
return false;
}

if (f.password.value=="")
{
alert("You must enter a password.");
f.password.focus();
return false;
}

submitted=true;
return(true);
//f.submit();
}
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
var f variable can store stuff like this...
All it is doing is settig a global variable (f) to the form object.
It makes it easier to reference the form elements by not having to type in:
document.Forname.ElementName.value="blah"
instead you can do something like this
Elem = document.FormNane.ElementName;
I then can do this
Elem.value="Blue"; //change value
Elem.style.background="blue; //Change CSS properties
This was a basic explaination, and I am not sure I anwered your question!
Eric
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 181
Eric,
Yes Eric, you answered my question very well!
Thanks for the help.
John Davis
 
 
subject: var f=document..loginForm; how can it work?
 
Threads others viewed
writing to a file using javascript
onsubmit: can you veto form submission without "return false"?
Date is automatically trimming in ie9,chrome and firefox
problem in name and password fields validation
return false from a function on error
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture