473,221 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

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 1725
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nescio | last post by:
hello, i have a form, that contains only 5 checkboxes, named box, box etc. there are no other textfields than this five checkboxes; people have to check at least one checkbox; i want to do...
3
by: Earl Teigrob | last post by:
I wanted my "Terms and Conditions" Checkbox control to participate in my ASP.NET validation just like all the the other controls on the page. After some time of searching the web for an example of...
5
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
5
by: nescio | last post by:
hello, i am making a form using php/html/javascript a part of the form is (email address) comming from a database. the amount of addresses is always different. every address has a checkbox....
1
by: oakura_ape | last post by:
I have inherited a site that I have ported to ASP.Net 2.0 within the site I have a checkbox in a datalist ItemTemplate as such: <TD width="4%"><INPUT class="rach" id="chk_vid" type="checkbox"...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
7
by: karen987 | last post by:
The code below is for a checkbox, in a form on an asp page. I want to make it mandatory for the user to click it. The other validation statements work fine, this one causes a problem though. The...
0
by: Ned Balzer | last post by:
I posted this this morning but it never went through, so I am trying again -- apologies for the duplication if so. I need to validate several checkboxes on an asp.net 2.0 page. I don't need to...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.