Another variant:-
Code:
<html>
<head>
</head>
<body>
<select id="myselectbox">
<option value="3">3 days</option>
<option value="10">10 days</option>
<option value="20">20 days</option>
<option value="30">30 days</option>
</select>
<input type="button" value="Add date" onclick="return addDate('Thursday, 31 December, 2012');" />
<input type="button" value="Add date" onclick="return addDate(new Date());" />
<br><br>
<input type = "text" id = "mytextbox" readonly>
<script type="text/javascript">
function addDate(addtoDate) {
var orignaltime = new Date(addtoDate).getTime();
var dropdowndateinMS = document.getElementById("myselectbox").value * 86400 * 1000;//day x seconds x milliseconds
var addedtime = orignaltime + dropdowndateinMS ;
var addedTimeInProperFormat = new Date(addedtime);
addedTimeInProperFormat = addedTimeInProperFormat.toDateString()
document.getElementById("mytextbox").value = addedTimeInProperFormat;
}
</script>
</body>
</html>
<script language=javascript> is long deprecated. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9).
The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.
Quizmaster: In sporting folklore, the word "golf" is often erroneously said to be an acronym of the phrase "gentlemen only, ladies ....." what?
Contestant: Fornicate.