I have two checkboxes with the same name, of course they have two different values. I need to check the value and if it's NA, don't populate a field with today's date, otherwise do populate a field with today's date. I'm including my code, although the if statement to check for the checkbox value doesnt work. I'm wondering if anyone can offer any suggestions. Thanks.
Code: Select all
<script type="text/javascript" language="JavaScript">
function displayAssistanceSelect(box)
{
var mydate=new Date()
var theyear=mydate.getYear()
if (theyear < 1000)
theyear+=1900
var theday=mydate.getDay()
var themonth=mydate.getMonth()+1
if (themonth<10)
themonth="0"+themonth
var theday=mydate.getDate()
if (theday<10)
theday="0"+theday
var displayfirst=themonth
var displaysecond=theday
var displaythird=theyear
// check the checkbox for NA - if it's NA, then don't populate the date field with today's date
if (document.casestatus.AssistanceSelect.value[i] == NA) {
document.casestatus.DateAssistance.value=''
} else {
document.casestatus.DateAssistance.value=displaythird+"-"+displayfirst+"-"+displaysecond
}
// get reference to form object, and to array of same-named checkboxes
var temparr = new Array(), f = box.form, boxgroup = f[box.name];
// loop through it
for (var i=0; i<boxgroup.length; i++)
{
// add the value of any checked box to next available slot in temparr
if (boxgroup[i].checked) temparr[temparr.length] = boxgroup[i].value;
// run the .join() method on the array (separator = ',') and output it to field
f.Assistance.value = temparr.join(',');
}
}
</script>