473,915 Members | 3,941 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check Box Problem

19 New Member
Hello all,
My problem,i have written a javascript to check whether the checkboxes are checked or not.If its not checked,i will get an alert message,if i checked then say it is checked.This condition is working for more than one data.If there is only one data and if i check that also,i am gettin an alert message and says its not checked.Please help me to solve this.

Javascript am using is,

Expand|Select|Wrap|Line Numbers
  1.     var total=""
  2.         for(var i=0; i < document.formname.field_id.length; i++)
  3.         {
  4.             if(document.formname.field_id[i].checked)
  5.                total +=document.formname.field_id[i].value + "\n"
  6.         }
  7.  
  8.        if(total=="")
  9.         {
  10.             alert("Please select one data") 
  11.             return false; 
  12.         }
Apr 6 '09 #1
2 1298
Dormilich
8,658 Recognized Expert Moderator Expert
I think that's because you get the field by "document.formn ame.field_id", which in this case returns a HTMLInputElemen t (an element node, that doesn't have the length property) instead of a HTMLCollection (several elements with the same name - an element node-set).

to overcome this use the DOM method getElementsByNa me() which always returns a node-set.
Apr 6 '09 #2
dmjpro
2,476 Top Contributor
I think your CheckBox has the same name then you better to do ...

Expand|Select|Wrap|Line Numbers
  1. var check_boxes = document.getElementsByName("checkbox_name");
  2. for(var i=0;i<check_boxes.length;i++){
  3.  var checkbox_ref = check_boxes[i];
  4.  //do whatever you want to do with the reference
  5. }
  6.  
Actually document.formNa me.elementName. length does not work when the element is single ;)
Apr 6 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
2776
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part of a form which amongst other submit buttons has a one particular submit button that if checked will send the form data (using GET) to a script that will email all the checked members.
8
2488
by: pw | last post by:
Hi, I need to create a function in javascript to check or uncheck all checkboxes in a form. From what I understand, I can do this either by specifying the name of the check box fields such as: function checkAll(list) { var o = document.getElementById(list); var c = o.checked; var f = document.forms.f; var a = f.item(list);
4
4070
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if the check box is being checked, some validation is performed. If the validation fails, I set cancel to true, and the check box is not checked afterwards. This is fine.
6
1970
by: Shannan Casteel via AccessMonster.com | last post by:
I'll explain as well as possible...not an experienced user...but learning. I am working on a database for different kinds of problems with machines. A user will be able to select a problem category from a combo box (i.e. Engine, Fuel, Electrical, Steering, Power Train, Brakes, Hydraulic, Chassis/Structure, etc.). Upon the users selection a series of cooresponding check boxes appears on the form with Problem Subcategories. For instance,...
1
4278
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will require checking a check box to tell which category something will pertain to. Well after each record is entered i want the check to remain with that record and auto clear when going to the next record so i can input something else if i have a...
6
2221
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time and resource consuming Try... Catch, which in iterative processing is totally unacceptable. -tom
12
14548
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
16
5686
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
1
1425
by: icetalks | last post by:
have a look at this code , its for logging the user in after checking his UserName and Password. dim check as boolean = false ... ... If txtUserName.Text.Length = 0 And txtPass.Text.Length = 0 Then MessageBox.Show("please Enter Your Name and Password") txtUserName.Text = "" txtPass.Text = ""
2
6195
by: Ben | last post by:
Hi! All of a sudden on a newer version of our application a check box on the "Produce Invoice" form cannot be checked. I did not do any changes to this form at all. Below are the things that I know so far about the problem: 1. On the new version of the application the check box cannot be checked 2. On the previous version of the application the check box can be checked 3. I did not do any changes to the form
0
10039
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11069
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7259
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.