Validate undefined number of checkboxes and textfields

Discussion in 'Javascript' started by JAPIO, Nov 16, 2005.

  1. JAPIO

    JAPIO Guest

    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?
     
    JAPIO, Nov 16, 2005
    #1
    1. Advertising

  2. JAPIO

    Joel Byrd Guest

    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) {
    if (form_name.gecontroleerdoor == "") {
    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.
     
    Joel Byrd, Nov 16, 2005
    #2
    1. Advertising

  3. JAPIO

    Lee Guest

    JAPIO said:
    >
    >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?


    Your PHP script will know how many of each element there are before
    it's finished writing the page. Let it generate the validation script.
     
    Lee, Nov 16, 2005
    #3
  4. JAPIO

    JAPIO Guest

    Currently i have the function below.

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

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

    for ( i=0 ; i < aantaldwgs ; i++ )
    {
    if ( f.goedgekeurd.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.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.
     
    JAPIO, Nov 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    How to format "Drop Down List" TextFields and ValueFields?

    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 4, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    13,248
    Eliyahu Goldin
    Jul 4, 2005
  2. J. Albers

    accessing textfields

    J. Albers, Jan 16, 2004, in forum: Java
    Replies:
    5
    Views:
    399
    J. Albers
    Jan 20, 2004
  3. Jim
    Replies:
    1
    Views:
    442
    Andrew Thompson
    Apr 10, 2004
  4. SteKel2002
    Replies:
    0
    Views:
    443
    SteKel2002
    Dec 21, 2003
  5. reto
    Replies:
    3
    Views:
    182
    Thomas 'PointedEars' Lahn
    Sep 23, 2007
Loading...

Share This Page