I am trying to find which check boxes the user checked (Which are created by pulling information from a db). How would I pass the information to a JavaScript function... The problem is that I want to check if the user checked any check box and which ones were checked for in insert into the db. I know I can hard code it, but I want this to be as dynamic as posibile. Here is what I have came up with so far....
this is the first page...Scripts
<SCRIPT LANGUAGE="JavaScript">
<!--
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
if ((opt[intLoop].selected) ||
(opt[intLoop].checked)) {
index = selected.length;
selected[index] = new Object;
selected[index].value = opt[intLoop].value;
selected[index].index = intLoop;
}
}
return selected;
}
function outputSelected(opt) {
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
strSel += sel[item].value + "/";
alert(strSel);
document.write("<input value="+strSel+" type=hidden name=facility>");
}
//-->
</SCRIPT>
<?php
$i=0;
while ($i<$z) {
print("<td width='15%'>");
print(" <input type='checkbox' name='fac_cd' value='$fac_cd[$i]'> $facSortDesc[$i]");
print("</td>");
if ($i%4==3) print("<tr width='15%'>");
$i++;
if ($i%4==0) print("</tr>") ;
}
?>
Here is the second page Scripts...
<?php
function IsDate($orig_data){
$data=explode("/","$orig_data");
$d=$data[0];
$m=$data[1];
$y=$data[2];
$res=checkdate($m,$d,$y);
if ($res==1) { return true;}
else { return false;}
}
//Connect to informix
$dbConnection=ifx_connect() or die("Connection to the Database failed");
//Query the database for facilities
$SELECT="SELECT fac_cd ";
$FROM= "FROM informix.events_fac ";
$builtQuery=$SELECT.$FROM;
$facilityQuery=ifx_query("$builtQuery", $dbConnection) or die("Query failed");
$rowsReturned=ifx_fetch_row($facilityQuery);
$z=0;
//Return the rows form Query
while (is_array($rowsReturned)) {
for(reset($rowsReturned); $fieldName=key($rowsReturned); next($rowsReturned)){
if ($fieldName==fac_cd) {
$fieldValue=$rowsReturned[$fieldName];
$fac_cd[$z]=trim($fieldValue);
}
}
$rowsReturned=ifx_fetch_row($facilityQuery);
$z++;
}
ifx_free_result($facilityQuery);
$dbConnection=ifx_close();
if ($title=="") $titleCheck="false";
else $titleCheck="true";
if (IsDate($strtDate)==false) $strtDateCheck="false";
else $strtDateCheck="true";
if (IsDate($endDate)==false) $endDateCheck="false";
else $endDateCheck="true";
if ($desc=="") $descCheck="false";
else $descCheck="true";
$i=0;
$facilityCheck="false";
while ($i<$z) {
if ($HQ==true) $facilityCheck="true";
$i++;
}
if ($titleCheck=="false" or $strtDateCheck=="false" or $endDateCheck=="false" or $descCheck=="false" or $facilityCheck=="false") {
echo $facilityCheck;
//header("Location: http://localhost/index/updateEvents.php?title=$titleCheck&strtDate=$strtDateCheck&endDate=$endDateCheck&desc=$descCheck&fac=$facilityCheck");
// exit;
}
?>