|
-
Oct 18th, 2007, 08:13 AM
#1
Thread Starter
Fanatic Member
URGENT[02/03] autocalculation of dates
Does anyone know offhand how to auto calcluate the date to increase it by 30 days and then by 60 days. I need to do the following on a web app I have the date that a user will enter in a textbox. As soon as the user tabs to the next textbox it should autocalc the date + plus 30 days and when the user tabs to the next textbox the date plus + 60 days should appear. Does anybody know how to do this ? Aspnet doesn't have to my knowledge the lostfocus event that was present when I was programming in VB6.
Last edited by Christopher_Arm; Oct 25th, 2007 at 08:30 AM.
-
Oct 18th, 2007, 09:15 AM
#2
Fanatic Member
Re: [02/03] autocalculation of dates
You will have to use some sort of Javascript to do this, most likely... Either that or AJAX (which ends up being Javascript in the end).
If your problem is solved, please use the Mark Thread As Resolved under Thread Tools!
Show Appreciation. Rate Posts!
-
Oct 18th, 2007, 09:58 AM
#3
Thread Starter
Fanatic Member
Re: [02/03] autocalculation of dates
 Originally Posted by MetalKid
You will have to use some sort of Javascript to do this, most likely... Either that or AJAX (which ends up being Javascript in the end).
You have totally lost me there since I have never used AJAX before and my web apps for the most part have not been that javascript reliant.
-
Oct 18th, 2007, 10:30 AM
#4
Re: [02/03] autocalculation of dates
This has nothing to do with AJAX. It's pure javascript.
You'll do a search on the onBlur method (for a textbox), in which you then call a javascript method that reads what's in textbox1, adds 30 days to it and immediately fills in that value into textbox2.
That should give you a good start.
-
Oct 23rd, 2007, 10:42 AM
#5
Thread Starter
Fanatic Member
Re: [02/03] autocalculation of dates
 Originally Posted by mendhak
This has nothing to do with AJAX. It's pure javascript.
You'll do a search on the onBlur method (for a textbox), in which you then call a javascript method that reads what's in textbox1, adds 30 days to it and immediately fills in that value into textbox2.
That should give you a good start.
Ok guys I put the Onblur Method in my Prerender of this textbox:
Code:
Private Sub TextBox6_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox6.PreRender
Me.TextBox6.Attributes.Add("onClick", ChangeDate())
End Sub
And then it calls this function ChangeDate:
Code:
Function ChangeDate()
Dim d As Date, r As Date, x As Date
d = CDate(TextBox4.Text)
r = d.AddDays(30)
x = d.AddDays(60)
TextBox6.Text = r
TextBox7.Text = x
End Function
I stepped through this with a breakpoint the program hits my function when the onblur is called and yet none of the values in textbox6 or 7 seem to change at all after making change in the initial value in textbox4. If I change 5/13/2007 in that textbox from 5/12/2007 all of the corresponding dates should increment accordingly. Why is this happening ?
-
Oct 23rd, 2007, 10:51 AM
#6
Re: [02/03] autocalculation of dates
Because you put it in onClick?
Also, you're doing this:
d = CDate(TextBox4.Text)
That's invalid javascript. For one, "TextBox4" isn't necessarily the ID that it will render as. Actually, all your javascript is wrong
I'd show you what to do but... you should search up on how to manipulate dates with javascript, shouldn't you? If you do get stuck, come back and then we'll give you the answer.
-
Oct 23rd, 2007, 11:06 AM
#7
Thread Starter
Fanatic Member
Re: [02/03] autocalculation of dates
 Originally Posted by mendhak
Because you put it in onClick?
Also, you're doing this:
d = CDate(TextBox4.Text)
That's invalid javascript. For one, "TextBox4" isn't necessarily the ID that it will render as. Actually, all your javascript is wrong
I'd show you what to do but... you should search up on how to manipulate dates with javascript, shouldn't you? If you do get stuck, come back and then we'll give you the answer.
Yes. I changed onblur to onclick and forgot about this..duh* slaps head*. I will research this and come back.
-
Oct 23rd, 2007, 12:21 PM
#8
Thread Starter
Fanatic Member
Re: [02/03] autocalculation of dates
I wasn't able to find anything out there on the subject except for the w3schools.com description of it which deals with a function call to uppercase and it was pretty brief. I am offically stuck. Can someone help me please ?
edit: hold up I found something in Javascript format..
var myDate = NewDate;myDate.setDate(myDate.getDate()+7);
But I am still lost on this subject.
Last edited by Christopher_Arm; Oct 23rd, 2007 at 12:37 PM.
-
Oct 24th, 2007, 08:44 AM
#9
Thread Starter
Fanatic Member
Re: [02/03] autocalculation of dates
so if I am correct in my assumption/ research then it should look something like this in Javascript ? Am I incorrect here and if not then how do I marry this logic to my specfic textbox ?
Code:
<html>
<head>
<script type="text/javascript">
function ChangeDate()
{
var myDate = NewDate;myDate.setDate(myDate.getDate()+7);
</script>
</head><body>
<input type="text" id="fname" onblur="ChangeDate()"></body>
</html>
-
Oct 25th, 2007, 09:36 AM
#10
Re: URGENT[02/03] autocalculation of dates
Ok, in basics, it would look like this
Code:
function ChangeDate()
{
var fulldate = document.getElementById('TextBox4').value;
var d = new Date(yyyy,mm,dd); //You must extract year, month date from fulldate.
var r = new Date(d.getDate() + 30);
var x = new Date(d.getDate() + 60);
document.getElementById('TextBox6').value = r;
document.getElementById('TextBox7').value = x;
}
The bits in green are the dynamic bits. So what would you do? Simple. This bit of javascript above, you are to generate from the codebehind. You must substitute, for example, "TextBox6" with TextBox6.ClientID.
Making sense now? YOu can test whether the javascript works first, by replacing the textbox1/2/3 with the rendered ID in the HTML source in the browser.
-
Oct 25th, 2007, 03:56 PM
#11
Thread Starter
Fanatic Member
Re: URGENT[02/03] autocalculation of dates
Ok I placed the call to the function here :
Code:
asp:textbox id="TextBox7" onblur = ChangeDate() style="Z-INDEX: 123; LEFT: 344px; POSITION: absolute; TOP: 160px"runat="server" Width="72px"></asp:textbox>
Then I followed up by placing the function in javascript here :
Code:
</form>
</body>
</HTML>
<script type="text/javascript">
function ChangeDate()
{
var fulldate = document.getElementById(TextBox4.clientID).value;
var d = new Date(yyyy,mm,dd); //You must extract year, month date from fulldate.
var r = new Date(d.getDate() + 30);
var x = new Date(d.getDate() + 60);
document.getElementById(TextBox6.clientID).value = r;
document.getElementById(TextBox7.clientID).value = x;
}
</script>
Just to test it. and nothing happened. There was no change in textbox7 based on the function call.
-
Oct 29th, 2007, 08:47 AM
#12
Thread Starter
Fanatic Member
Re: URGENT[02/03] autocalculation of dates
anybody ?
-
Oct 29th, 2007, 09:35 AM
#13
Re: URGENT[02/03] autocalculation of dates
You missed a vital bit.
This bit of javascript above, you are to generate from the codebehind.
That means you have to use Page.RegisterClientScriptBlock, passing it that javascript in a string, in which you would then substitute those bits for their codebehind .ClientIDs.
Code:
Page.RegisterClientScriptBlock("myscript",@"<script language=""JavaScript"">
function ChangeDate()
{
var fulldate = document.getElementById('" + TextBox4.ClientID + @"').value;
var d = new Date(yyyy,mm,dd);
var r = new Date(d.getDate() + 30);
var x = new Date(d.getDate() + 60);
document.getElementById('" + TextBox6.clientID + @"').value = r;
document.getElementById('" + TextBox7.clientID + @"').value = x;
}
</script>");
Also keep in mind that the code above is a guide. It is pseudo code. Not the actual thing, but close to it. You need to do a bit of work yourself, such as replacing yyyy, mm, dd.
-
Oct 30th, 2007, 10:39 AM
#14
Thread Starter
Fanatic Member
Re: URGENT[02/03] autocalculation of dates
 Originally Posted by mendhak
You missed a vital bit.
That means you have to use Page.RegisterClientScriptBlock, passing it that javascript in a string, in which you would then substitute those bits for their codebehind .ClientIDs.
Code:
Page.RegisterClientScriptBlock("myscript",@"<script language=""JavaScript"">
function ChangeDate()
{
var fulldate = document.getElementById('" + TextBox4.ClientID + @"').value;
var d = new Date(yyyy,mm,dd);
var r = new Date(d.getDate() + 30);
var x = new Date(d.getDate() + 60);
document.getElementById('" + TextBox6.clientID + @"').value = r;
document.getElementById('" + TextBox7.clientID + @"').value = x;
}
</script>");
Also keep in mind that the code above is a guide. It is pseudo code. Not the actual thing, but close to it. You need to do a bit of work yourself, such as replacing yyyy, mm, dd.
My code did have problem saying that PageScriptBlock did not support the active schema and I had to erase the part where language was specified as Javascript because it gave a red underline indicating this was not recognized.
Also should this code be placed before the </body> tag ? or after it ?
-
Oct 31st, 2007, 06:34 AM
#15
Re: URGENT[02/03] autocalculation of dates
That code goes into the codebehind. It generates the Javascript.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|