je*******@gmail .com wrote:
This is raw code, as it exists in my cfm, not rendered by
firefox/ie.
Which means that it is not the code that is producing the errors. The
code that the browser actually gets is the only code that is interesting
for diagnosing the problems that produce errors on the browser.
Originally, I wrote the validation script for a single
form....named "form",
The name "form" is not particularly good, partly because form controls
already have a property named 'form', and partly because it says nothing
about what the form is for.
so there wasn't an additional variable
in the function. so "document.thisF orm" was simply
"document.f orm" and it worked perfectly with no java/browser
errors whatsoever. As I originally stated "does nothing"
I should've said that an error is generated: "thisForm has no
properties".
That is not what the error actually said. it said - document.thisFo rm
has no properties (or something similar). The _precise_ error message
may not mean much to you yet but you will eventually see that they have
a very close relationship with what is going wrong on the browser.
This is likely due to the bracket notation you mentioned.
Not due to, but avoidable with.
<snip>
The input elements do indeed have names and ID's so
please don't misunderstand.
I understood what I read. If that was a misunderstandin g then I was
reading the wrong material (and only you have the power to influence
that).
In the interest of not providing gobs upon gobs of
code, I chose to explain that the include statements
had properly syntaxed form input elements, primarily
checkboxes.
So you were saying 'I have some code I would like help debugging, and
here is some other code that may be similar in some respects'.
Should I then take to your meaning that the function
should read thusly?:
function chkAll(thisBox, group,thisForm) {
var inputs = document[thisForm].getElementsByT agName("input") ;
Not if you pass - this.form - as the third argument. The - form -
property of form controls is a reference to the form element, and any
property of the document being referenced by the form's name attribute
is also a reference to the form element, so the - document[ someName ] -
part is redundant as soon as you are passing the reference to the form
into the function from the event handler. If you passed -
this.form.name - into the fucntion then what you would get is the name
of the form element (if it has one) but then using that name to look-up
the reference is a bit silly as the reference was where the name was
look up prior to passing it.
if(document[thisForm].getElementById (thisBox).check ed == true)
Comparing the boolean - checked - property with boolean true to give a
boolean result for the - if - expression is redundant as the comparison
will always produce the dame result as the - checked - property already
has.
Even if the - document[thisForm] - was being resolved into a reference
to FORM element, FORM elements do not have a - getElementById - method
(only documents do), and the document level method will not work
properly unless the element ID is unique.
{ for (i=0;i<inputs.l ength;i++){
The variable - i - is not declared in this function, that makes it
global. It does not need to be global and so should be subject to the
axiom; no variable should be given any more scope than it absolutely
needs. It should be a function local variable (as that is the most local
scope available), so declared within the function. Habitually using
global variables a loop counters is particularly problematic as it
becomes easy for a function to be called in the body of one loop that
itself uses a global loop counter with the same name. Unexpected
consequences include infinite loops and loops that end sooner than
expected.
if(inputs[i].id == group){
inputs[i].checked = 1;
<snip>
You decided to ignore my advice to assign true/false instead of 1/0?
Will that succesfully pass the form name (in this case form1)
No.
to the function and check all the boxes with the id 'northChk'
in only the form 'form1'?
IDs should be unique within an HTML document. You should fix that design
misconception before you do anything else.
Given the mark-up code you (appear to) have, passing the reference to
the form as:- onClick="chkAll ('chkAllNorth', 'northChk',this .form);" -
the fucntion:-
function chkAll(thisBox, group, theForm){
var i, inputs = theForm.getElem entsByTagName(" INPUT");
var checkIt = thisForm.elemen ts[thisBox].checked;
for (i=0;i<inputs.l ength;i++){
if(inputs[i].id == group){
inputs[i].checked = checkIt;
}
}
return true;
}
- should do the job of the original.
I apologize that I cannot try it for myself at the
moment because I am out of the office and do not have the pages
available to me until the morning.
Richard.