By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

What does this code mean ?

P: n/a
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[i];
if (/comment_fieldset/.test(oForm.className)) // <--- WHAT DOES THIS
LINE MEAN ?
{
oForm.onsubmit = function()
{
return addComment(this);
}
}
}
}
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


RobertTG wrote:
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[i];
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);
}

Jul 23 '05 #2

P: n/a
"RobertTG" <rt*@mailinator.com> wrote in message
news:d7**********@reader1.panix.com...
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[i];
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...asp?frame=true

Regards,
John MacIntyre
http://www.johnmacintyre.ca
Specializing in; Database, Web-Applications, and Windows Software
Jul 23 '05 #3

P: n/a
RobertTG wrote:
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[i];
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.
}
}
}

--
Rob
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.