473,394 Members | 1,785 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,394 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 1731
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.