Array issue

From: Date: Wed, 25 Sep 2002 02:26:07 +0000
Subject: Array issue
Groups: php.windows 
Request: Send a blank email to php-windows+get-15991@lists.php.net to get a copy of this message
I have this in my code: <input type="checkbox" name="tack[]" value="<?echo odbc_result($rs3,"dTackID");?>"> I'm passing this to a javascript function like this to check all checkboxes: onClick="this.src = check(document.forms[0].elements['horse[]'], document.forms[0].elements['trailer[]'], document.forms[0].elements['tack[]'])" My problem is this...if there are two horse/trailer/tack checkboxes on the page...it will check/uncheck them fine. However, if there is only one element in the array when passed in, it will do nothing to the checkbox. No errors show up or anything, just nothing happens to the lone checkbox. Here is the javascript code for those interested: <SCRIPT LANGUAGE = "JavaScript"> var checkflag = "false"; function check(field, field1, field2) { if (checkflag == "false") { if(field) { for (i=0; i<field.length; i++) {field[i].checked = true;} } if(field1) { for (i=0; i<field1.length; i++) {field1[i].checked = true;} } if(field2) { for (i=0; i<field2.length; i++) {field2[0].checked = true;} } checkflag = "true"; return "images/button_unselectall.gif"; } else { if(field) { for (i=0; i<field.length; i++) {field[i].checked = false;} } if(field1) { for (i=0; i<field1.length; i++) {field1[i].checked = false;} } if(field2) { for (i=0; i<field2.length; i++) {field2[i].checked = false;} } checkflag = "false"; return "images/button_selectall.gif"; } } </script> If you can help that would be great, thanx in advance, Kit _________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx

« previous php.windows (#15991) next »