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

Validate undefined number of checkboxes and textfields

I have a form which is generated by PHP. This form contains one
textbox, one textarea and one checkbox all at one row. This row is
being repeated multiple times according to the number of results from a
database.

gecontroleerdoor[]
opmerkingen[]
goedgekeurd[]

The thing i want to do is to check if all the textboxes have a value
and that all the checkboxes are checked with true or false as outcome.

Can someone help me out with this?

Nov 23 '05 #1
2 1413
If the array indexes are just integers that are being incremented
(gecontroleerdoor[0], gecontroleerdoor[1], etc...), then you could use
something like the following (javascript):

var all_have_values = true;
var i = 0;

while (form_name.gecontroleerdoor[i]) {
if (form_name.gecontroleerdoor[i] == "") {
var all_have_values = false;
break;
}
i++;
}

This example is assuming that gecontroleerdoor[] is the textbox array
and you want to check to see that all these textboxes have values (are
not empty). You can apply similar code to the other form elements.
The syntax may not be perfect, but I think this should basically work.

Nov 23 '05 #2
Currently i have the function below.

function checkCheckboxes(f)
{
var numberofrows = <?= $numberofrows?>;
var afgekeurd = 0;

for ( i=0 ; i < numberofrows; i++ )
{
if ( f.gecontroleerddoor[i].value == '' ) afgekeurd++;
}

for ( i=0 ; i < aantaldwgs ; i++ )
{
if ( f.goedgekeurd[i].checked == false ) afgekeurd++;
}
}

But this produces the following error in FireFox:
Error: f.gecontroleerddoor has no properties

Which refers tot the following line:
if ( f.gecontroleerddoor[i].value == '' ) afgekeurd++;

The form i used for the input is created by the following code:

foreach( $batchdwgs as $batchdwg )
{
echo "<tr><td valign=\"top\">" . $batchdwg->batchdwg_naam . "<input
name=\"batchdwgid[]\" type=\"hidden\" value=\"" .
$batchdwg->batchdwg_id . "\" /></td>
<td valign=\"top\"><input name=\"gecontroleerddoor[]\" type=\"text\"
value=\"" . $batchdwg->batchdwg_gecontroleerddoor . "\"></td>
<td valign=\"top\"><textarea name=\"opmerkingen[]\" cols=\"30\"
rows=\"2\">" . $batchdwg->batchdwg_opmerkingen . "</textarea></td>
<td align=\"center\"><input name=\"goedgekeurd[]\" type=\"checkbox\"
value=\"1\"" . (( $batchdwg->batchdwg_goedgekeurd )?" CHECKED":"") . "
onChange=\"checkCheckboxes(this.form);\"></td>
</tr>";
$i++;
}

I'm wondering what i'm doing wrong.

Nov 23 '05 #3

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

Similar topics

6
by: LRW | last post by:
I have no idea if this is more a PHP question or Javascript question, because my problem hinges equally on both. I have a PHP script that queries a database and creates a list of rows for each...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
1
by: babu17 | last post by:
hi, i have a list of checkboxes, the number of checkboxes is dynamic. All the checkboxes have same name. i am trying to get the length of selected checkboxes. <input type=checkbox name=name1...
1
by: Jon | last post by:
Hello all, I need to validate client-side a group of checkboxes to make sure at least 1 ic ticked. Does anyone have any examples please? Thanks. Jon
13
by: Oleg Konovalov | last post by:
Hi, I am working on a web application which among other things uses DHTML, Java and Javascript. It populates web page based on the contents of the database (resultset), and next to each row...
6
by: dream2rule | last post by:
Hello All, I am trying to validate multiple checkboxes whose values are stored in an array using php. I have been trying from a really long time but nothing's working out. Can anyone help? ...
0
by: zappbrannigan | last post by:
I am using a MSBDC and have some textfields and checkboxes bound to it. When i changed the database from access to mySQL the textfields still work fine but the checkboxes dont react. If i switch it...
10
dmjpro
by: dmjpro | last post by:
Let's see at my code fragment. var checkBoxes = document.getElementsByTagName("input"); for(var i=0;checkBoxes.length;i++){ if(checkBoxes.type.toLowerCase()=="checkbox" && checkBoxes.checked){...
4
faugustin
by: faugustin | last post by:
Hi, I have a problem. I have av form with textfields, textareas and a vector type fieldset of checkboxes. Everything but the checkboxes works fine, they result in "array" in the field in the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
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...
0
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,...
0
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...

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.