473,396 Members | 2,070 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,396 software developers and data experts.

Multiple text boxes with the same name

Hi all

I'm a first-time poster and would appreciate some help with a problem
I'm having. I have an HTML form (UPD_BUDG) which includes 10
checkboxes, all with the same name (Apply_Phasing_CB) but different
values. On its own (i.e. before I add any JS) the form works fine.

I need to add an onSubmit function which counts how many of the boxes
are checked. Here is the script I have used:

function check_form()
{
var check_count = 0;
for(i = 0; i < 10; i++)
{
if (document.forms.UPD_BUDG.Apply_Phasing_CB[i].checked)
{
check_count++;
}
}
return check_count;
}
When I run this I get the error message
'document.forms.UPD_BUDG.Apply_Phasing_CB[...].checked is not an
object'. I am running this on IE 5.

Can anyone advise me on what I'm doing wrong?

Thanks

Ellie
Jul 20 '05 #1
2 7110

"Ellie100" <el***********@hotmail.com> schreef in bericht
news:45**************************@posting.google.c om...
I need to add an onSubmit function which counts how many of the boxes
are checked. Here is the script I have used:
....
When I run this I get the error message
'document.forms.UPD_BUDG.Apply_Phasing_CB[...].checked is not an
object'. I am running this on IE 5.

Can anyone advise me on what I'm doing wrong?


Must be an error in your HTML (didn't close the form tag perhaps?), because
the following works for me:

<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function check_form() {
var obj = document.UPD_BUDG.Apply_Phasing_CB;
var check_count = 0;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) check_count++;
}
return check_count;
}
</script>
</head>

<body>
<form name="UPD_BUDG">
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="button" onclick="alert(check_form())" value="Check">
</form>
</body>
</html>
JW

Jul 20 '05 #2
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> wrote in message news:<3f***********************@news.euronet.nl>.. .

Must be an error in your HTML (didn't close the form tag perhaps?), because
the following works for me:

<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function check_form() {
var obj = document.UPD_BUDG.Apply_Phasing_CB;
var check_count = 0;
for (var i = 0; i < obj.length; i++) {
if (obj[i].checked) check_count++;
}
return check_count;
}
</script>
</head>

<body>
<form name="UPD_BUDG">
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="checkbox" name="Apply_Phasing_CB"><br />
<input type="button" onclick="alert(check_form())" value="Check">
</form>
</body>
</html>
JW


Thanks JW. Referring to the object as a variable, as you did, rather
than directly, seems to have done the trick. If anyone can explain
why this should be, I'd be interested!

Thanks again

Ellie
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joey | last post by:
Say a customer inserts into a sql database field (NUMINSERTS) the number 6. On the following page, I want to build a table that displays 6 input boxes, since the customer said they wanted 6 text...
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
4
by: Dave Parrin-Bull | last post by:
Hi all, I have been asked (nay told!) to do a quiz for a webpage at work, now I can do the basic things like getting the radio boxes up there and assign values to them but here is what they...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.