martialtiger said:
I'm having a hard time trying to figure out why the following
validation works on FF and not IE versio 6.0
But you don't specify what 'works' is, or even what not working is.
function checkForm()
{
var errmsg = "Please correct all errors before continuing:
\n\n";
Don't allow posted code to auto-wrap, manually wrap it at about 70
characters. The preferred indent is 2 or 4 spaces.
var errors=0;
//var formElement = document.vpform;
If there is a form in the document with a name of 'vpform', then
formElement will be a reference to it. If there is more than one form
with that name (names don't need to be unique) then formElement will be
a collection.
var agree = document.vpform.agree.checked;
agree may now be:
1. a boolean, either -true- if the element exists, has a
checked property and it's checked or
2. -false- if it's not
3. if the element doesn't exist, an error will result - you
can't access properties of non-existent objects
4. if the element does exist but doesn't have a checked property,
agree will be 'undefined', which will type-convert to 'false'
in an -if- test.
IE adds most names and all IDs as global variables that reference the
element they belong too. In the case of duplicate names, only the first
is added; form controls with names and ids aren't added though the same
element outside a form (i.e. when not a form control) are.
As a result, creating a local variable with the same name as an element
can lead to confusion so change the local variable 'agree' to maybe
'b_agree' to show it's a boolean.
//formElement["agree"].checked;
That simply returns the value of the checked property, if you want to
set it to something (say make it checked):
formElement["agree"].checked = true;
var bundleID = document.vpform.bundleID.value;
//formElement["bundleID"].value;
As above... Also again you've used a local variable with the same name
as a form element (bundleID), change that.
There is no need to test against -false-, you can just do:
if (agree){
{
if (bundleID != 0) {
return true;
Do you really mean the number zero? Or do you mean "" (empty string)?
}
else
{
alert("You must select a lesson you wish to
receive.");
return false;
}
}
else
{
alert("You must select the checkbox to agree with the
terms.");
This makes me think you need:
var o;
if ( (o=document.forms['vpform'])
&& (o=o.elements['agree'])
&& o.checked )
{
// agree exists and has been checked
}
else
{
// either:
// this browser doesn't support the forms collection or
// there isn't a form named 'vpform' or
// it doesn't have an element named 'agree' or
// 'agree' doesn't have a checked property or
// 'agree' isn't checked
// Deal with it...
}
The quick 'n dirty way is:
if (!document.vpform.agree.checked){
// it's not checked, deal with it.
}
[...]
Why is '-->' there? Don't use HTML comments anywhere inside script
elements. Once upon a time, it was thought necessary to 'hide' scripts
with an opening <!-- and a closing //-->, but that's not been necessary
since Netscape 2/IE 3 (about 10 years ago).
You'll notice I commented out what I thought were the problems.
Much better to post a minimal 'working' example that shows the error,
explain what actually happens (i.e. the error) and what you want to
happen. The more effort you put into posting the question, the faster
you'll get answers (and likely more of them).