I am trying to create a script where depending on the value of a drop down box, it automaticly fills a textbox with a quarter, 2 quarters or 2 quarters away from the given date. So for value quarter 1, box1 would be "1-1-2011" and box2 would have "1-4-2011" filled in. At the moment I see nothing happening when it comes to changing dates. I am a beginner and have been trying to make this work for days. Sorry if I've overlooked an obvious problem.
The elements are as follows:
<div>
<label>Periode</label>
<select name="pchoice" id="pchoice" onChange="calcdates()">
<option value="moddate">Zelf invoeren</option>
<option value="quarter1">1e Kwartaal</option>
<option value="quarter2">2e Kwartaal</option>
<option value="quarter3">3e Kwartaal</option>
</select>
</div>
<div>
<label>Datum </label> <input id="startDate" name="startDate" maxlength="10" style="width: 6em;"/> t/m <input id="endDate" name="endDate" maxlength="10" style="width: 6em;"/>
</div>
The script:
<script type="text/javascript" charset="utf-8">
$(document).ready(
function() {
var datepickerparam = {
dateFormat : 'dd-mm-yy',
dayNamesMin : [ 'Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za' ],
monthNames : [ 'Januari', 'Februari', 'Maart', 'April','Mei', 'Juni','Juli', 'Augustus', 'September','Oktober', 'November', 'December' ]
};
$("#startDate").datepicker(datepickerparam);
$("#endDate").datepicker(datepickerparam);
});
function calcdates(){
var w = document.pchoice.selectedIndex;
var selected_text = document.pchoice.options[w].value;
var commencedate = new Date("01-01-2011");
var end = new Date();
//make dynamic with some variable
switch(selected_text){
case "quarter1":
$("#startDate").val(commencedate);
$("#endDate").val(commencedate+90);
break;
case "quarter2":
$("#startDate").value='12-03-2011';
$("#endDate").value='12-06-2011';
break;
case "quarter3":
$("#startDate").value='13-06-2011';
$("#endDate").value='13-09-2011';
break;
case "moddate":
$("#startDate").value = '';
$("#endDate").value ='';
break;
}
}