473,780 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to reference inputs when the name ends with '[]'

8 New Member
Hi Guys,

I am am trying to validate multiple check box. It works fine when checkbox name is like chkSectionInter ested but when i add [] to the name chkSectionInter ested[], then i can validate any more.

I need to keep [] so that i can save data using php collected from this page.

If i remove [] from checkbox name then php only gets last selected value from the check box please help. I have been looking for two days but nothin seems to work.

Expand|Select|Wrap|Line Numbers
  1. function checkBox()
  2. {
  3.     alert("Q1");
  4.  
  5. // Validate Check boxs
  6.     //-------------------------
  7.     var filledIn = false;     
  8.     alert(document.forms[0].chkSectionInterested.length);
  9.     // Use the length property to iterate through each Checkbox
  10.     // to determine if a selection has been made
  11.  
  12.     // ----- Area Of Interest 
  13.  
  14.     for (var counter=0; counter<document.forms[0].chkSectionInterested.length; counter++)
  15.      {
  16.             if (document.forms[0].chkSectionInterested[counter].checked == true)
  17.                {
  18.                   filledIn = true;
  19.  
  20.                    //else{
  21.                if (document.forms[0].chkSectionInterested.checked == true)
  22.                {
  23.                    filledIn = true;
  24.                }
  25.                }
  26.     }
  27.        if (filledIn == false)
  28.        {
  29.            alert('Please select your area of interest');
  30.            document.forms[0].chkSectionInterested[0].focus();
  31.            return(false);
  32.           }   
  33.      return (true);
  34. }
  35.  
[HTML]
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Beauty" style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Wellness " style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">
<input class="clsSecti onInterested" type="checkbox" name="chkSectio nInterested[]" value="Saloon" style="font-family: Arial; font-size: 10pt; border: 0px solid #C0C0C0; padding: 0">[/HTML]


PHP Code

[PHP]
$strSectionInte rested="";
$count=count($c hkSectionIntere sted);
for($i=0;$i<$co unt;$i++){$strS ectionIntereste d="$strSectionI nterested$chkSe ctionInterested[$i], ";}[/PHP]

ALL THE CODE WORKS FINE BUT DOES NOT VALIDTAE IF I REMOVE [ ] FROM CHECKBOX NAME AND IF I REMOVE [ ] THEN PHP GET ONLY THE LAST SELECTED VALUE FROM THE CHECK BOX AND ABOVE ALL I HAVE TO VALIDATE SO THAT USER ATLEAST SELECT 1 OPTION.
Sep 5 '07 #1
6 1654
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN!

Use document.getEle mentsByName():
Expand|Select|Wrap|Line Numbers
  1. var checkboxes = document.getElementsByName("chkSectionInterested[]");
Sep 5 '07 #2
inamul
8 New Member
Welcome to TSDN!

Use document.getEle mentsByName():
Expand|Select|Wrap|Line Numbers
  1. var checkboxes = document.getElementsByName("chkSectionInterested[]");

Thanks for your prompt reply i tried but i still get error may be i am doing some thing wrong.

could you please implement it in the same code so that i have complete example.
Sep 5 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Try this:
Expand|Select|Wrap|Line Numbers
  1.     var checkboxes = document.getElementsByName("chkSectionInterested[]");
  2.     for (var counter=0; counter<checkboxes.length; counter++)
  3.      {
  4.             if (checkboxes[counter].checked == true)
  5.                {
  6.                   filledIn = true;       
  7.                }
  8.     }
  9.     if (filledIn == false)
  10.        {
  11.            alert('Please select your area of interest');
  12.            return false;
  13.       }   
  14.     return true;
Sep 5 '07 #4
pbmods
5,821 Recognized Expert Expert
Changed thread title to better describe the problem.
Sep 5 '07 #5
inamul
8 New Member
Try this:
Expand|Select|Wrap|Line Numbers
  1.     var checkboxes = document.getElementsByName("chkSectionInterested[]");
  2.     for (var counter=0; counter<checkboxes.length; counter++)
  3.      {
  4.             if (checkboxes[counter].checked == true)
  5.                {
  6.                   filledIn = true;       
  7.                }
  8.     }
  9.     if (filledIn == false)
  10.        {
  11.            alert('Please select your area of interest');
  12.            return false;
  13.       }   
  14.     return true;
Thanks for your help It works.. This really is an excellent forum.

Thanks again
Sep 6 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
Glad you got it working and you're welcome. Post again anytime should you need help.
Sep 6 '07 #7

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

Similar topics

16
1648
by: Michael G | last post by:
I have an api that uses reference as arguments. void function(double z, short &x, short &y){} some calculations are done on z and then the results are being passed back out in x and y. The values the i need to pass to this function are pointer to shorts. short * x1; short * y1;
0
2988
by: maxim mat | last post by:
Hi I need to build client for web service. But when I'm using Visual Studio .NET to add Web Reference, I get error: "Custom tool error: Unable to import WebService/Schema. Unable to import binding 'controllerSoapBinding' from namespace 'http://Bla-Bla-Bla'. Unable to import operation 'getClient'. The datatype 'Array' is missing. " Some problem when I try to use wsdl.exe tool in .NET. I get: Schema validation warning: Type 'cww:Class' is...
0
1644
by: Dhananjayan | last post by:
Hi, I have a webservice(eg.IStringServicePort) running on Axis, iam able to create a java client for the same and invoke the service and obtain the result. I wanted to create a .Net client(C#) for the same..For that I did the following thing I added a web reference for the service thru "Add Web Reference", It got added successfully, But iam unable to find the web reference in my c# class. Because of that iam not able to invoke the...
1
1015
by: enantiomer | last post by:
In my project that I am working on, within visual studio 2005 I would like it so that I can group my multiple web services under one web reference name. I need this because I am reusing code that directly consumes my business services project. For example, BusinessServices project has - SecurityServices, UserServices classes BusinessServices.Web project has - SecurityServices, UserServices web services, which basically map to the...
0
2349
by: Steven Bolard | last post by:
Hello, I am trying to port my .net 1.1 application to 2.0. I am using vs2005. I am trying to get my webservices to run and although i can compile them and and get wsdl and service descriptions through internet explorer when hitting the ..asmx url, i cannot generate a proxy class to use in my winforms assembly. When i try to generate a proxy, i get no error message but nor do i get a reference.vb so there is no type info. If i then try...
9
6405
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using this code: Dim test3 As TextBox test3 = CType(e.Item.FindControl("edit_name"), TextBox)
0
789
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
3
14056
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
5
1340
by: laredotornado | last post by:
Hi, I have a number of INPUTs on my page that look like <input id="form_items" name="form_items " size="15" type="text" value="..." /> How do I refer the last one of these on my page? Thanks, - Dave
0
9636
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
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10075
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,...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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
6727
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
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
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.