|
|
|
ถามแนวคิด เมื่อทำการเลือกวันที่เริ่มต้น แล้วต้องการให้แสดงวันสิ้นสุด คะ |
|
|
|
|
|
|
|
จัดให้ครับ นอนไม่หลับ
Code (JavaScript)
<script type="text/javascript">
function Pad(input, pad_length, pad_string, pad_type) {
var half = '', pad_to_go;
var pad_repeater = function (s, len) {
var collect = '', i;
while (collect.length < len) {collect += s;}
collect = collect.substr(0,len);
return collect;
};
input += '';
pad_string = pad_string !== undefined ? pad_string : ' ';
if (pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH') { pad_type = 'STR_PAD_RIGHT'; }
if ((pad_to_go = pad_length - input.length) > 0) {
if (pad_type == 'STR_PAD_LEFT') { input = pad_repeater(pad_string, pad_to_go) + input; }
else if (pad_type == 'STR_PAD_RIGHT') { input = input + pad_repeater(pad_string, pad_to_go); }
else if (pad_type == 'STR_PAD_BOTH') {
half = pad_repeater(pad_string, Math.ceil(pad_to_go/2));
input = half + input + half;
input = input.substr(0, pad_length);
}
}
return input;
}
function calcEndDate(frm){
var objDate =new Date();
var setRangeVal = frm.range_num.value;
var setRangeType = frm.range_type.options[frm.range_type.selectedIndex].value;
var setStartDate = frm.start_date.value;
var objEndDate = frm.end_date;
if(setRangeVal != "" && setStartDate != ""){
var dateSplited = setStartDate.split('/');
if(dateSplited.length == 3){
objDate.setFullYear(dateSplited[2], (parseInt(dateSplited[1])-1), dateSplited[0]);
if(setRangeType == "Days"){
objDate.setDate(objDate.getDate()+parseInt(setRangeVal));
}else if(setRangeType == "Months"){
objDate.setMonth(objDate.getMonth()+parseInt(setRangeVal));
}else if(setRangeType == "Years"){
objDate.setFullYear(objDate.getFullYear()+parseInt(setRangeVal));
}
if(!isNaN(objDate.getDate()) && !isNaN(objDate.getMonth()) && !isNaN(objDate.getFullYear())){
objEndDate.value = objDate.getDate() + '/' + Pad((objDate.getMonth()+1), 2, '0', 'STR_PAD_LEFT') + '/' + objDate.getFullYear();
}
}
}
}
</script>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="range_num" id="range_num" size="2" onkeyup="javascript:calcEndDate(this.form);" />
<select name="range_type" id="range_type" onchange="javascript:calcEndDate(this.form);">
<option value="Days" selected="selected">Days</option>
<option value="Months">Months</option>
<option value="Years">Years</option>
</select>
<br />
<input type="text" name="start_date" id="start_date" onkeyup="javascript:calcEndDate(this.form);" />
<br />
<input type="text" name="end_date" id="end_date" readonly="readonly" />
</form>
ส่วนเรื่อง data validation ไปจัดเองเองนะ
|
|
|
|
|
Date :
2011-03-14 03:53:59 |
By :
PlaKriM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะคะ :)
|
|
|
|
|
Date :
2011-03-14 20:40:30 |
By :
koori |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|