473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Can anybody explain this code pls?

I was going through this code from Negrino's JavaScript for the WWW
book. I have 2 questions:
1. Why has the author used validForm(passForm)? I mean what is
'passForm' in the function?
2. And its relation to this line - <form onsubmit="return
validForm(this)" action="">; What is 'this' here?

Thanks in advance.
Roohbir

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password Check</title>
<script language="Javascript" type="text/javascript">
<!-- Hide script from older browsers

function validForm(passForm) {
if (passForm.passwd1.value == "") {
alert("You must enter a password")
passForm.passwd1.focus()
return false
}
if (passForm.passwd1.value != passForm.passwd2.value) {
alert("Entered passwords did not match")
passForm.passwd1.focus()
passForm.passwd1.select()
return false
}
return true
}

// End hiding script -->
</script>
</head>
<body bgcolor="#FFFFFF">
<form onsubmit="return validForm(this)" action="">
Your name: <input type="text" size="30" />
<p>Choose a password: <input type="password" name="passwd1" /></p>
<p>Verify password: <input type="password" name="passwd2" /></p>
<p><input type="submit" value="Submit" /<input type="reset" /></p>
</form>
</body>
</html>

Oct 23 '06 #1
2 1273
roohbir wrote:
I was going through this code from Negrino's JavaScript for the WWW
book. I have 2 questions:
1. Why has the author used validForm(passForm)? I mean what is
'passForm' in the function?
Just a variable name.
2. And its relation to this line - <form onsubmit="return
validForm(this)" action="">; What is 'this' here?
In that context it is the form, and it gets passed to the specified variable
name in the function.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Oct 23 '06 #2
roohbir wrote on 23 okt 2006 in comp.lang.javascript:
I was going through this code from Negrino's JavaScript for the WWW
book. I have 2 questions:
1. Why has the author
You would have to ask him, we can only surmize.
... used validForm(passForm)? I mean what is
'passForm' in the function?
"this" of "validForm(this)"
2. And its relation to this line - <form onsubmit="return
validForm(this)" action="">; What is 'this' here?
"this" represents the object where it called,
in this case the form object.

so:

passForm.passwd1.value

which idealy should have been:

passForm.elements['passwd1'].value

gives the value that could also be described as:

document.forms['thisFormName'].elements['passwd1'].value

or perhaps:

document.getElementById('thisFormId').elements['passwd1'].value

=======
return false
prohibits the form's submission.

=======
<script language="Javascript" type="text/javascript">
<!-- Hide script from older browsers
both lines show that either the book is outdated
or the skils of the writer,
as just this would be optimal in practice and encouraged:

<script type='text/javascript'>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: andrew | last post by:
Hi, I posted this message recently, but received no response, so I figured I'd try again. I can't find anybody who can tell me what's going on here. I'm having a problem with fieldsets in IE...
4
by: siddurampure | last post by:
PLZ ANYBODY KNOWS WHY ICAP PROTOCOL IS USED?
1
by: qushui_chen | last post by:
Anybody can explain the directly send mail to pop3 Server? 1.if it is use Smtp protocol? 2.if i write one Smtp Server?
0
by: thattommyhallll | last post by:
i am doing the problems at http://www.mathschallenge.net/index.php?section=project one problem involved finding factors, i used def divisors(n): divisors = set() for i in range(1, math.ceil(n...
2
by: Clemens Vasters | last post by:
"Is anybody from Microsoft reading this?" Well ... actually .... no .... welll ... maybe if you're really lucky. Let me explain ... My name is Clemens Vasters and I am a Program Manager on the...
1
by: webinfinite | last post by:
HI, I ran across a code written by somebody else. Since I am new to C++, could you please explain what each of "const *" means in this code snippet as well as the last "const"? Tool const*...
4
by: pk | last post by:
Hello. I'm new to YUI but I see it's a set of a very useful tools. So I'm trying to use it :) And I have first problem. Could anybody help me and explain why the slider which I created on my...
11
by: Gabriel | last post by:
Hi anybody intested in developing JSLibrary by yourslef??The project "Knut" has risen up,intend to building a new JSLibrary,more detail visit http://groups.google.com/group/knutDN ,we hope you to...
2
by: maifs | last post by:
hi..... can anybody tell me that how can i save my all application's work. mean that how can i save the images,circles,rectangle,lines or etl together.. if somebody knows it then plz explain me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.