
Originally Posted by
TimeTracker
JesDisciple - I apologise for not providing some code. I have wondered for years whether it is possible. None of the Julian calendar JavaScript calculators that I have seen have this facility and so I thought it might be too difficult to code. But as I have found out Dynamic Forum can do some pretty amazing things with JavaScript.
That functionality was probably excluded just because most people don't need/want it rather than due to the additional complexity or difficulty of writing it.

Originally Posted by
TimeTracker
This is the source code for the calculator. I have since modernised it, but this was the original given to me in 2000.
The modernized source would have been more appropriate, but if you haven't changed what you supplied it should be alright. (Note that I'm not complaining about the fragment - just the age.)

Originally Posted by
TimeTracker
Perhaps an if...else statement might be helpful. If not one, then the other.
Yes, but I'm using an abbreviated if...else known as a conditional (or ternary - "three-part") statement. This is handy when only the value of one variable depends on the condition - and conditional statements can be nested inside each other, but each should be parenthesized if it's not the entire statement. Here's the syntax:
Code:
var x = boolean ? ifBooleanIsTrue : ifBooleanIsFalse;

Originally Posted by
TimeTracker
AD will be the value in the text field input manually (selectedIndex is not practical)
... What's "selectedIndex"? EDIT: Oh, I now understand; never mind.

Originally Posted by
TimeTracker
var year would be either value, which means the code would appear first as a separate function or included with the present function. Would further text fields (hidden) be required to assist with the calculations?
I'm not understanding... BC vs AD is decided by the radio buttons, right?

Originally Posted by
TimeTracker
Also is there a way to allow only one radio button to be selected if a wrong decision is made and the other selected as well? In my browser both appear clicked.
Give each set of radio buttons the same 'name' attribute value (as I have below) and the browser will make them work like that.
This is also required for me to identify the radio buttons as a single set in the JavaScript (using the mechanism you already have, which I prefer).
Code:
<!--
function determineModuleAndWeekday(form) {
// Calculate Julian Day.
var day = Number(form.day.value);
var month = Number(form.month.value);
var year = form.years.value == 'BC' ? (Number(form.year.value) - 1) * -1 : Number(form.year.value);
var jd = gregorianDate2JulianDate(day, month, year);
form.julianDay.value = jd;
etc.
}
// -->
Code:
<form name="moduleForm">
<table>
<tr>
<th ALIGN=LEFT><font color="#000000">Enter Julian or Old Western Style
Date:-</font></th>
</tr>
<tr>
<td><input type="text" name="day" size=10><font color="#000000">(day [1..31])</font></td>
</tr>
<tr>
<td><input type="text" name="month" size=10><font color="#000000">(month
[1..12])</font></td>
</tr>
<tr>
<td><input type="text" name="year" size=10><input type="radio" name="years" value="AD">AD <input type="radio" name="years" value="BC">BC
(year [include the century])</td>
</tr>
<tr>
<td ALIGN=LEFT><input type="button" value="Calculate"
onClick="determineModuleAndWeekday(document.moduleForm)"><input TYPE="RESET" VALUE=" Reset "ONCLICK="putFocus(0,0)" "WIDTH="50"></td>
</tr>
</form>
</table>

Originally Posted by
TimeTracker
Also, does there have to be two radio buttons if the AD value does not need changing? Only if BC is selected would there be a need for the function. Otherwise the calculations should default to AD if the BC radio button is not selected.
I implemented this in the conditional statement above.

Originally Posted by
TimeTracker
var year text field would obviously remain hidden [type="hidden"]. Your suggestions will be much appreciated.
Don't you need to know the number of years whether they're BC or AD? Why do you need to hide the 'year' text field? (I'm not even sure JavaScript can change a field's type...)
Bookmarks