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

check some radiobuttons

Hello,
until now I have not found the mistake that I made. My source code for
checking how many checkboxes or radiobuttons are used:

<script language="JavaScript"><!--
function pruefen(){return true}
//-->
</script>
<script language="JAvaScript1.1"><!--
function pruefen(f){
var i;
var k=0;
document.forms[f].elements;/* here I can't find any syntax for an
object(mainly I was trying with a book and there is no description
about objects)*/

for(i=0; i < f.elem.length; i++){

if ('checkbox' == elem[i].type)
{
if(elem[i].checked)
k++;
}
}return true; //(or k)
}
//-->
After that I need to check k.

<form onSubmit="return pruefen(this)"></form>

Many thanks
Jul 20 '05 #1
1 2978
Bjoern Jackschina wrote on 02 Dec 2003:
Hello,
until now I have not found the mistake that I made. My source
code for checking how many checkboxes or radiobuttons are used:

<script language="JavaScript"><!--
function pruefen(){return true}
//-->
</script>
<script language="JAvaScript1.1"><!--
1) Don't use SGML comments in SCRIPT blocks. It's not necessary.
2) Don't use the language attribute. It has been deprecated in favour
of type (type="text/javascript"). Moreover, type is /required/,
language is not.
3) Version 1.3 of JavaScript is four years old. Finding a browser
that does not support it would be difficult enough to find. The odds
of coming across a browser that doesn't support version 1.1 are even
smaller.
4) As language is deprecated, browsers don't have to use it to
determine what scripts to execute and what scripts to ignore.
Besides, there's a better way of testing if a property or method is
implemented:

if ( 'undefined' != typeof object.property ) {
// property supported

OR

if ( undefined != object.property ) {
// property supported
function pruefen(f){
var i;
var k=0;
document.forms[f].elements;/* here I can't find any syntax for
an object(mainly I was trying with a book and there is no
description about objects)*/
When you called this function in the intrinsic event, you passed the
entire form object reference (this). That means that 'f' is
equivalent to:

document.forms['nameOfFormF']

If you want the elements collection, all you need do is:

f.elements
for(i=0; i < f.elem.length; i++){

if ('checkbox' == elem[i].type)
{
if(elem[i].checked)
k++;
}
}return true; //(or k)
}
This block is very difficult to read. That is what formatting is for.
You should have presented it like this before posting it:

for ( i = 0; i < f.elements.length; ++i ) {
if ('checkbox' == elem[i].type) {
if (elem[i].checked) k++;
}
}
return true;
//-->
After that I need to check k.
How, where, and what for?
<form onSubmit="return pruefen(this)"></form>


Replace both SCRIPT blocks with this:

<SCRIPT type="text/javascript">
function pruefen( f ) {
var k = 0, elems = f.elements;
var size = elems.length;

if (size) {
if ('undefined' == typeof elems[0].type) {
// The type property is the only non-1.0 property used in
// this function. The document.forms collection is v1.1, but
// we get the array via the this operator. The length
// property /should/ be v1.0 as other length properties are.

// If this block is entered, type is not defined.
}
}
for (var i = 0; i < size; ++i ) {
if ('checkbox' = elems[ i ].type) {
if (elems[ i ].checked) k++;
}
}
}
</SCRIPT>

I don't know what you wanted to do with k (how and when you were
going to check it), so I just incremented it. If you want to access
it outside of this function, you'll either have to return it, or
declare it global (declare elems with var, though). You also didn't
say under what conditions this function might return true or false,
so I didn't include that either. If the submission should only occur
if one or more boxes were checked, you could return k (if zero, it
will evaluate as false, or as true if one or more).

Hope that helps somewhat,
Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2

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

Similar topics

1
by: discomiller | last post by:
Mario Mueller: Hello *, radiobuttons belong to other radiobuttons by the "name="any_value"" attribut. Thats a fakt. I got the following XML:...
1
by: --=|3s|=-- | last post by:
Hi, I'm trying to create a form in VISUAL BASIC .NET wich shows values of records from a customers table. For example a form wich shows the name, surname and sex of a person. For the name &...
11
by: Rourke Eleven | last post by:
I have looked and searched. What good is the databind property on Radiobuttons? How does one go about actually using it? What is a good resource on this? I understand that I can easily get/set...
2
by: Chris Ashley | last post by:
I have a couple of RadioButtons both with the same GroupName. Is there any way I can use a RequiredFieldValidator to ensure that at least one of the RadioButtons in the group is selected? Setting...
0
by: PaulS | last post by:
Hello! I put on Form PictureBox and I set big image. Next I put many radiobuttons (80) on PictureBox, but I have problem. I want that 10 radiobuttons have own Checked, next part of 10...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, GroupBox1 contains 3 radiobuttons. Is there a builtin way - a Container property - in the groupbox control to determine which radiobutton is checked - if any? I did not see anything...
4
by: PedroVision | last post by:
I have a VB 2005 form with 140 different radiobuttons... Some are "checked", some are not... I want to reset all radiobuttons to "unchecked". I've been searching and trying differnet...
8
by: =?Utf-8?B?UmljaA==?= | last post by:
If you enclose a group of radiobuttons (option buttons in MS Access) in an option group control (a frame control) in Access -- the frame control will return the index of the option button that is...
0
by: | last post by:
I am using radiobuttons in a gridview, and not a column of radiobuttons. I have one cell in each row with several radiobuttons that the user has to choose a radiobutton within each row. How can I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.