![Picture of Nadia Trojan Picture of Nadia Trojan](/graphics/unknown.gif)
Nadia Trojan - 2011-10-26 11:10:49
Hi,
I am making a staff availability form in which workers enter what shifts they are able to work throughout a chosen week and then the details get emailed. I have a drop down select box from which the user can select the starting saturday of the week. If the user selects the last saturday and it is Wednesday for example I would like to disable the check boxes for Saturday, Sunday, Monday and Tuesday. Below is a snippet of what I have tried to do from reading information on the web:
<?php
function disableCheckBoxes($start_saturday){
$myFile = "disable.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "DISABLE");
fclose($fh);
return "DISABLE";
}
?>
...
<head>
<script language="javascript" type="text/javascript">
function StartSaturday() {
selected_saturday = document.getElementById("start_saturday");
selected_saturday_text = selected_saturday.options[selected_saturday.selectedIndex].text;
startSaturday = "<?=disableCheckBoxes(selected_saturday);?>";
alert(startSaturday);
}
</script>
</head>
...
<form id="form" name="StaffAvailabilityForm" method="post" action='sendStaffAvailabilityForm.php'>
<select name="start_saturday" id="start_saturday" onchange="StartSaturday(); window.location.reload(true);">
<option>
<?php
date_default_timezone_set ('Australia/Melbourne');
echo date("d-m-Y", strtotime("last saturday"));
?>
</option>
<option>
<?php
date_default_timezone_set ('Australia/Melbourne');
echo date("d-m-Y", strtotime("next saturday"));
?>
</option>
<option>
<?php
date_default_timezone_set ('Australia/Melbourne');
$date = date("d-m-Y", strtotime("next saturday"));
$week_1 = strtotime("+1 week", strtotime($date));
echo date("d-m-Y", $week_1);
?>
</option>
</select>
<div id="embedded_chkbx"><input type="checkbox" name="sat_am" id="sat_am" /></div>
<div id="embedded_chkbx"><input type="checkbox" name="sun_am" id="sun_am" />
<button type="submit">Submit</button>
<div class="spacer"></div>
</form>
Obviously at the moment the checkboxes dont get disabled/enabled however I would like to read from the file disable.txt which or not the checkbox should be disabled. I understand that there needs to be more logic written to determine the day etc. However at the moment I am just attempting to get the OnChange to call the PHP function however it doesn't excute the PHP function disableCheckBoxes when called from StartSaturday(). Would do I need to do for this function to be executed?
Any help would be much appreciated.
Thank you,
Kind Regards,
Nadia