Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic date calculation Problem !!

Status
Not open for further replies.

puteri

Programmer
Joined
Apr 15, 2003
Messages
9
Location
MY
hi...

I used pop up calendar to display start date. It works ,
but I have to do automatic calculation for the end date.
So when ever we click the start date pop up calendar, the
text field for end date will automatically display the end date based on the formula i have created.

I tried to used onClick , onChange, onKeyUp for the handler, but it doesn't works. ANy idea ?? thanks in advance...

this is my code:

<script language="JavaScript">


function calenddate() {
var datestart = document.myForm.schestart.value;
var fm = document.myForm;

if (document.myForm.schestart.value != "" ){
// my formula
end = 02-03-2006 ;
fm.schecomp.value = end;
}
}
</script>

<form name="myForm" method="post">
date start:
<input name="schestart" type="text" size="15" onClick="calenddate()">&nbsp;
<a href="javascript:cal1.popup();"> <img src="../cal/cal.gif" width="16" height="16" >


Date end : <input name="schecomp" type="text" size="15" readonly>

<script language="JavaScript">

var cal1 = new calendar1(document.forms['WOForm'].elements['schestart']);
cal1.year_scroll = true;
cal1.time_comp = false;

</script>
</form>
 
Don't know whatever there are. But, this is what?
>[tt]end = 02-03-2006 ;[/tt]
(literally 2 minus 3 minus 2006 equal to minus 2007)

 
sorry for the confusing statement.
It just a default value for testing purpose.
the problem is the calenddate() function didn't even execute.
I just wondering the right place for me to call the callenddate() function. It is at the right place ?? thanks again. :)
 
Test this out. (Also why don't you close the anchor?)
[tt]
<a href="javascript:cal1.popup();[red]calenddate()[/red]"> <img src="../cal/cal.gif" width="16" height="16" >[red]</a>[/red]
[/tt]
Also use onclick on the textbox is no good and has annoying side-effect. After changing the anchor above, change the onclick to onblur say at the textbox.
[tt]
<input name="schestart" type="text" size="15" on[blue]blur[/blue]="calenddate()">[/tt]

There might be other side-effect to iron out. Start testing like that?
 
hi...tsuji,
thanks for your feedback, i've tried to do according your suggestions, but still no luck. :(
there javascript error "Object doesn't support this property or method" I use IE whenever to trace javascript error.
And furthermore, i tried to put all the callendate()function inside cal1 javascript, but still cannot.
hope u'll have brilliant idea...thanks
 
there javascript error "Object doesn't support this property or method"

i tried to put all the callendate()function inside cal1 javascript, but still cannot.

Your function is not called "callendate()" - it is called "callend[!]d[/!]date()". Maybe this is why you are getting errors?

Or, it could be because "calendar1" (as in "new calendar1(..." is not defined anywhere.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
hi...sorry, i have other works to be done.

well, i tried, but now i faced another problem. well this is my code after some modifications. it's not the whole code, just the important portion.

<!-- <script language="JavaScript"> -->
<script type="text/javascript">

function count(){

var totaldur = 450;
//alert(dateend);

var fm = document.MyForm;
var datestart = fm.start;
alert (datestart); // i did'nt get this value, it keep appear [object] in the alert message box.

var pday2 = datestart.substring(0,2);
var pmonth2 = datestart.substring(3,5);
var pyear2 = datestart.substring(6,10);

//var d2 = new Date(pyear2 , eval(pmonth2-1) , pday2);
//well this is just my calculatin
//convert totaldurations (in hour) to days (ceil:rounds up a decimal number to the next largest number)
var day = totaldur / 24;
day = Math.ceil(day)
alert (day);

var now = new Date();
//do u think which one is the right one ?? i want to display the end date in the schecomp text box.

var countdur = new Date(now.getTime() + (day * 24 * 60 * 60 * 1000));
var end =datestart.setDate(datestart.getDate()+day);

fm.schecomp.value = countdur;
alert(end);
alert(countdur);

}
</script>

<form name="MyForm" method="post">

<%java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd-MM-yyyy");
java.util.Date currentTime_1 = new java.util.Date();
String dateString = formatter.format(currentTime_1);
%>
date start :
<input name="schestart" type="text" size="15" onKeyUp=count()>&nbsp;
<a href="javascript:cal1.popup();count()"> <img src="../cal/cal.gif" width="16"
height="16" border="0"></a>

end date :
<input name="schecomp" type="text" size="15" readonly>&nbsp;

<script language="JavaScript">

var cal1 = new calendar1(document.forms['MyForm'].elements['start']);
cal1.year_scroll = true;
cal1.time_comp = false;

</script>

well, the code is quite messy because i still try and error to find the solutions, but the main problem is i didn't get the latest value of date start after i choose from the pop up calendar.

hope u guys out there could help me plz.... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top