hi guys
I'm currently working on a project where registered uers can add a buyer or a seller specifications
On my buyerspec page I validate(with javascript) the contents of "Location" (see pic of location.jpg) to see if the user has selected a location by clicking on one of the other tabs.

CODE TO DISPLAY THE CHECKBOXES
CODE
$sql = "select * from jos_li_location where loc_id <= '3' and active = '1' order by loc_id";
$locations = $db->get_results($sql);
foreach($locations as $location) {
echo "<tr>";
echo "<td width='5'></td>";
echo "<td><input type='checkbox' name='location[]' value='$location->loc_id' />$location->loc_descr</td>";
echo "</tr>";
}
If the validation is successfull, the user can click on the next tab and complete the rest of the form
On the form submission the values entered is posted to an action page members/buyer/addspecb.php and inserted into a mysql db
(if db queries look a bit strange, it's because I'm using ez_sql.php)
To add the location(s) (can add more than one location per buyer spec)
i call the following function InsertLocations($specid, $locations, $db) which receives and array of location values from the form
CODE
function InsertLocations($specid, $locations, $db) {
if($locations) {
foreach ($locations as $key => $value) {
$sql = "insert into jos_li_locationlink(loc_id, spec_id) ".
"values ('$value', '$specid')";
$db->query($sql);
}
}
}
My problem is with the checkbox name (name="location[]")
CODE
echo "<td><input type='checkbox' name='location[]' value='$location->loc_id' />$location->loc_descr</td>";
My javascript validation(below) wich is called when the user clicks on the next tab wich toggles the various tabs to display or not,
likes the checkbox name="location", but not name="location[]". With the checkbox name attribute set to name="location" only the last selected checkbox value
gets passed to function InsertLocations($specid, $locations, $db).
If the checkbox attribute is set to name="location[]", then I get javascript erros, but without the validation check the values of the location[] checkbox
array is inserted perfectly in the db via function InsertLocations($specid, $locations, $db).
CODE
function countLocationb(form) {
var total=0;
frm = document.frmAddBuyerSpec;
for(var i=0; i < frm.location.length; i++){
if(frm.location[i].checked) {
total++;
}
}
if( total == 0 ) {
return false;
} else {
return true;
}
}
if false then user must enter at least one location
Is there some sort of workaround for this
I've been beating myself up for the last couple of days trying to workaround this, but nnnooooo solution yet
Thanx in advance for the help guys