Hello everyone,
I am using javascript and I have a radio button that the user selects and I have a function to see which button was selected, but i'm trying to use the return of that if statement in another statement.
Basically another part of the function is dependent on what the user selects in the radio button.
Here is what I have so far (I have some things in there that might not work because i'm trying to figure out what works):
Code:
<script type="text/javascript">
function getSelectedRadio() {
len = document.dates.dep.length
// returns the array number of the selected radio button or -1 if no button is selected
if (document.dates.dep[0]) { // if the button group is an array (one button is not an array)
for (var i=0; i<len; i++) {
if (document.dates.dep[i].checked) {
return i
}
}
} else {
if (document.dates.dep.checked) { return 0; } // if the one button is checked, return zero
}
// if we get to this point, no radio button is selected
return -1;
}
function Calculate() {
var i = getSelectedRadio();
if (i == -1) {
alert("Please select if Marine entered Delayed Entry Program");
} else {
if (document.dates.dep[i]) {
return document.dates.dep[i].value; }
else {
return document.dates.dep.value; }
}
if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 &&
document.dates.dayDEAF.value < 01 && first return from above) {
document.dates.yearDEP.value = (document.dates.yearDEAF.value);
document.dates.monthDEP.value = (document.dates.monthDEAF.value);
document.dates.dayDEP.value = (document.dates.dayDEAF.value);
document.dates.yearPEBD.value = (document.dates.yearDEAF.value);
document.dates.monthPEBD.value = (document.dates.monthDEAF.value);
document.dates.dayPEBD.value = (document.dates.dayDEAF.value);
}
else if (document.dates.yearDEAF.value < 1985 && document.dates.monthDEAF.value < 01 &&
document.dates.dayDEAF.value < 01 && second return from above) {
document.dates.yearPEBD.value = (document.dates.yearAFADBD.value);
document.dates.monthPEBD.value = (document.dates.monthAFADBD.value);
document.dates.dayPEBD.value = (document.dates.dayAFADBD.value);
document.dates.yearDEP.value = "N/A";
document.dates.monthDEP.value = "N/A";
document.dates.dayDEP.value = "N/A";
}
}
</script>
I color coded in red the returns i'm trying to reference and where they need to be. Is this possible, and if so how can I do it? I haven't been able to find anything on the internet so far. Any help is greatly appreciated!