web form to populate a date field and automatically populate other date fields with dates.

Posted on 2005-04-25
Last Modified: 2012-06-21
i am trying to design a web form that allows a user to add a date

so for eg:

the user enters 01/01/2005 in the first box

there are 5 other date fields in the form

each of these is populated with a date based on the value entered in the first box

so the other  date fields will populate with

1st blank date field automatically updated with =  01/01/2005 + 7 days
2nd blank date field automatically updated with = 01/01/2005 + 14 days
3rd blank date field automatically updated with = 01/01/2005 + 46 days

any help or guidance on this would be greatly appreciated. thank you in advance

Question by:westlondonsun
    LVL 12

    Expert Comment

    Dim D As Date

    D = Text1.Text  'whatever user entered

    1stDateField =  DateAdd("d", 7, D)
    2ndDateField DateAdd("d", 14, D)
    3rdDateField DateAdd("d", 46, D)


    Author Comment

    a little confused.

    on the above line :
    D = Text1.Text  'whatever user entered

    how does the browser know that d = whatever the user entered?

    Does the user have to click submit. i dont acctually want the user to press any buttons. i want the user to simply enter the date in dd/mm/yyyy format in the first text field and then the others automatically update??

    thanks for ur speedy reply
    LVL 12

    Expert Comment

    I have never done web programming but what I can say is that you need some sort of event.  Does the Text field give any client side event.  I think there is OnChange and OnExit.  If your users will be moving focus to another control after entering the date then use OnExit if not you may have to use OnChange (which will happen every keypress I think) then check if the text in the control is a valid date
    LVL 11

    Expert Comment

    To populate an input box in a HTML page, you need to find the name of the input box from the html. Here is a sample i just plucked from one of my other answers:

    Add a webbrowser control (press control+t then select "Microsoft Internet Controls" and add it to your form) and a command button and paste the following. When the page is fully loaded - press the command button:

    Private Sub Command1_Click()
     MsgBox WebBrowser1.Document.All("myName").Value
    End Sub

    Private Sub Form_Load()
     WebBrowser1.Navigate2 ""
    End Sub

    If you look at the source for the page, the input box is defined by:

     <input type=text name=myName value="testing.....">

    And i used the name property to reference the control and get the value.


    And if you want to put text into the textbox, use:

    WebBrowser1.Document.All("myName").Value = "myText"
    LVL 13

    Accepted Solution

    Try this (the dates will be updated after the first boxt losft focus):

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

       Function UpdateDates()
                if isdate(form1.originalDate.value) then
                form1.originalDatePlus7.value = dateadd("d", 7, cdate(form1.originalDate.value))
                      form1.originalDatePlus14.value = dateadd("d", 14, cdate(form1.originalDate.value))
                      form1.originalDatePlus46.value = dateadd("d", 46, cdate(form1.originalDate.value))
                      form1.originalDatePlus7.value = "invalid date"
                      form1.originalDatePlus14.value = "invalid date"
                      form1.originalDatePlus46.value = "invalid date"                  
                end if
       End Function

    <body bgcolor="#FFFFFF" text="#000000">
    <form name="form1" method="post" action="">
     <p>Insert your date:
      <input type="text" name="originalDate" onchange="UpdateDates()">
     <p>Date + 7d
      <input type="text" name="originalDatePlus7">
     <p>Date +14d
      <input type="text" name="originalDatePlus14">
     <p>Date + 46d
      <input type="text" name="originalDatePlus46">

    Author Comment

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <form name="form1" method="post" action="">
    Dim txtcharge As Date
    dim txthearing As Date
    dim txtplea As Date
    dim txtpretrial As Date
    dim txttrial As Date
    dim txtsentence As Date

    txtcharge = Text1.Text  'whatever user entered

    txthearing =  DateAdd("d", 7, D)
    txtplea DateAdd("d", 7, D)
    txtpretrial DateAdd("d", 35, D)
    txttrial DateAdd("d", 49, D)
    txtsentence DateAdd("d", 63, D)

      <input name="txttrial" type="text" id="txttrial2">
        <input name="txtcharge" type="text" id="txtcharge">
        date of charge</p>
        <input name="txthearing" type="text" id="txthearing">
        date of first hearing</p>
        <input name="txtplea" type="text" id="txtplea">
        date of plea</p>
        <input name="txtpretrial" type="text" id="txtpretrial">
        date of pre trial</p>
      <p> date of trial</p>
        <input name="txtsentence" type="text" id="txtsentence">
        date of sentence</p>
        <input type="submit" name="Submit" value="Submit">

    can anyone see from the above code, what i have missed or not put into the code yet

    LVL 3

    Expert Comment

    You did put a text box on your frm and called it Text1 didn't you?

    Are you developing for Windows or for the web? That looks like a web form with VB added? ASP? ASP.NET?

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now