开发者

Update 2nd Textbox Based On Popup Calendar Selection

I am using the JavaScript-based popup calendar from dynamic drive named "Xin's Popup Calendar" and it works perfectly. But, I want to be able to adjust the date of a 2nd textbox based on the selection.

For example, I want to be able to automatically adjust it to +1 month of whatever date was selected in the popup. How can I do that?

Here is an example:

<input type="text" name="firstinput" size=20>
<small><a href="JavaScript:showCal('Calendar1')">Select Date</a></small>

<p>
<input type="text" name="second开发者_运维技巧input" size=20>
<small><a href="JavaScript:showCal('Calendar2')">Select Date</a></small>
</p>

If the firstinput date is 3/21/10, I want the secondinput to change to 4/21/10 at the same time.


There are two parts to this: (1) a function to add a month to a data and (2) the change event handler to the textbox. This solution is very specific to the Xin Pop Up Calendar.

function addMonth(d,month){
 t = new Date (d);
 t.setMonth(d.getMonth()+ month) ;
 if (t.getDate() < d.getDate())
  {
   t.setDate(0);
  }
 return t;
} 

$("input[name='firstinput']").change(function(){

var dt = $(this).val();
var yr = dt.substring(0,4);
var mo = dt.substring(5,7);
var dy = dt.substring(8,10);

var firstDate=new Date();
firstDate.setFullYear(yr,mo-1,dy);

var secondDate = addMonth(firstDate,1);
$("input[name='firstinput']").val(secondDate.getFullYear() + "/" + secondDate.getDate() + "/" + secondDate.getMonth()+1);

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜