I would like to thank AQHost for his input on the checkboxes his suggestions definitely work

ie.,

form blah blah blah...post to some phppage.php>
<INPUT id='check1' type=checkbox name=checkbox1[] value='1'>
<INPUT id='check1' type=checkbox name=checkbox1[] value='2'>
<etc etc etc>
</form>

then use on phppage.php

$checkbox1array = $_POST[checkbox1];

foreach($checkbox1array as $key => $value)
{
Do interesting stuff;
}

however when i declare the name checkboxes as arrays ...ie
checkbox1[] ....my javascript code to for client side validation...to check if any check boxes are checked...craps out...and i cant fix it???

apparently an array of check boxes is automatically created when you have multiple checkboxes on a form with the same name...
so this declaration... checkbox1[]... is only necesary for PHP but not for Javascript or ASP.

anyone know how to fix this Javascript function when using this declaration "checkbox1[]"?

function valchkboxes()
{
/ this function ensures that the checkboxes are checked before sending form to the server/

returnValue = false;

var K = document.Delete.checkbox1.length;//problem here

for (var i= 0 ; i<K ; i++)
{
if (document.Delete.checkbox1.checked == true)
{ returnValue = true;}
}

  if  (returnValue == false)
         {alert("You must check a check box");}

  return returnValue;

}

var K = document.Delete.checkbox1.length;//problem here i tried
var K = document.Delete.checkbox1[].length;//doesnt work

AQHost

    You have to refer to the checkboxes in terms of their position in the form.

    This should get you started:

    function valchkboxes()
    {
    / this function ensures that the checkboxes are checked before sending form to the server/

    returnValue = false;

    for (var i=0; i < document.Delete.elements.length; i++)
    {
    if((document.Delete.elements.type == 'checkbox') && (document.Delete.elements.checked == true))
    { returnValue = true;}
    }

    if (returnValue == false)
    {alert("You must check a check box");}

    return returnValue;

    }


    -- Jason

      many thanks, jburfield, this works fine....merci beacoup

        Write a Reply...