469,323 Members | 1,614 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Checkbox Validation Works on FF but not IE

I'm having a hard time trying to figure out why the following
validation works on FF and not IE versio 6.0

function checkForm()
{
var errmsg = "Please correct all errors before continuing:
\n\n";
var errors=0;
//var formElement = document.vpform;
var agree = document.vpform.agree.checked;
//formElement["agree"].checked;
var bundleID = document.vpform.bundleID.value;
//formElement["bundleID"].value;

if (agree != false)
{
if (bundleID != 0) {
return true;
}
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.");
return false;
}
}
-->

You'll notice I commented out what I thought were the problems.

TIA!

May 16 '06 #1
4 1643
martialtiger wrote:
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.

if (agree != false)
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).
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 16 '06 #2
Thanks Rob for the response. I found the problem and appreciate the
tips.

May 17 '06 #3
martialtiger wrote:
Thanks Rob for the response. I found the problem and appreciate
the tips.


But you did not say what the problem was, for the second time now.
Usenet does not work this way.
PointedEars
--
A true translation needs neither omissions nor addings.
It is its own content.
-- me, 2003
May 22 '06 #4
JRS: In article <53****************@PointedEars.de>, dated Mon, 22 May
2006 23:20:26 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :
martialtiger wrote:
Thanks Rob for the response. I found the problem and appreciate
the tips.


But you did not say what the problem was, for the second time now.
Usenet does not work this way.


He was not addressing you, O socially retarded one; and the article to
which you respond is getting on for a week old.

When, if ever, do you propose to stop behaving like a six-year-old?

Please read FYI28/RFC1855, and keep doing so until you understand how
News should be used, or until you have been cured by a paediatric
psychotherapist.

--
© John Stockton, Surrey, UK. yyww merlyn demon co uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
May 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by nescio | last post: by
5 posts views Thread by DotNetJunkies User | last post: by
34 posts views Thread by clinttoris | last post: by
5 posts views Thread by nescio | last post: by
1 post views Thread by oakura_ape | last post: by
reply views Thread by Ned Balzer | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.