What does this code mean ?

R

RobertTG

Someone please translate the code below into English...
Particularly the indicated line
Thanks


function attachComment()
{
var aForms = document.getElementsByTagName("FORM");
for (var i = 0; i < aForms.length; i++)
{
var oForm = aForms;
if (/comment_fieldset/.test(oForm.className)) // <--- WHAT DOES THIS
LINE MEAN ?
{
oForm.onsubmit = function()
{
return addComment(this);
}
}
}
}
 
J

John

RobertTG said:
Someone please translate the code below into English...
Particularly the indicated line
Thanks


function attachComment()
{
var aForms = document.getElementsByTagName("FORM");
for (var i = 0; i < aForms.length; i++)
{
var oForm = aForms;
if (/comment_fieldset/.test(oForm.className)) // <--- WHAT DOES THIS
LINE MEAN ?
{
oForm.onsubmit = function()
{
return addComment(this);
}
}
}
}


Hi Robert,

I believe the line of code you are referring to checks if the className
contains the text "comment_fieldset".

Check out
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthtest.asp?frame=true

Regards,
John MacIntyre
http://www.johnmacintyre.ca
Specializing in; Database, Web-Applications, and Windows Software
 
S

small

RobertTG said:
Someone please translate the code below into English...
Particularly the indicated line
Thanks


function attachComment()
{
var aForms = document.getElementsByTagName("FORM");
for (var i = 0; i < aForms.length; i++)
{
var oForm = aForms;
if (/comment_fieldset/.test(oForm.className)) // <--- WHAT DOES THIS
LINE MEAN ?
{
oForm.onsubmit = function()
{
return addComment(this);
}
}
}
}


/comment_fieldset/ is a Regular Expression Object object, and test is
one of the methods of it.

see this:

Microsoft® JScript®
test Method Language Reference
Version 3


See Also Applies To


--------------------------------------------------------------------------------

Description
Returns a Boolean value that indicates whether or not a pattern exists
in a searched string.
Syntax
rgexp.test(str)
The test method syntax has these parts:

Part Description
rgexp Required. A Regular Expression object. Can be a variable name or
a literal.
str Required. The string to test a search on.


Remarks
The test method checks to see if a pattern exists within a string and
returns true if so, and false otherwise.
The RegExp object is not modified by the test method.

The following example illustrates the use of the test method:


function TestDemo(re, s)
{
var s1;
// Test string for existence of regular expression.
if (re.test(s))
s1 = " contains ";
else
s1 = " does not contain ";
// Get text of the regular expression itself.
return(s + s1 + re.source);
}
 
R

RobG

RobertTG said:
Someone please translate the code below into English...
Particularly the indicated line
Thanks


function attachComment()
{
var aForms = document.getElementsByTagName("FORM");

A collection of the documents forms is 'put into' the variable
'aForms', which is now a kind of array so that aForms[0] references the
first form in the document, aForms[1] the second, etc.
for (var i = 0; i < aForms.length; i++)
{
var oForm = aForms;


For every form that is referenced by aForms...
if (/comment_fieldset/.test(oForm.className)) // <--- WHAT DOES THIS
LINE MEAN ?

if the classname if the form contains the text 'comment_fieldset'...
{
oForm.onsubmit = function()
{
return addComment(this);
}

attach the function 'addComment()' to the onsubmit handler with
a reference to the form as a parameter ('this' will refer to the
form that is being submitted).

When the form is submitted, addComment() runs and probably returns
either true or false depending on the outcome of whatever it does.
Whatever value addComment() returns is returned to the onsubmit
handler, and if it's 'false', the form will not be submitted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top