Javascript select date question

Discussion in 'Javascript' started by SamuelXiao, May 17, 2009.

  1. SamuelXiao

    SamuelXiao Guest

    Hi, I am writing an application about a search booking system. When a
    user input a date in an input tag yyyy-mm-dd, there is automatically
    output the inputed date + 7 days, it is like:

    choose your period: From: <input>________</input> To
    <input>_______</
    input>

    When a user input 2009-05-17, the <input> after To will automatically
    output 2009-05-24.

    I have been doing for hours but still cannot do it. Is it must to
    use
    Ajax? I read the datepicker sample of Jquery UI, but it can choose
    one date only. Are there any way to do it?

    Any help would be appreciated.
     
    SamuelXiao, May 17, 2009
    #1
    1. Advertising

  2. SamuelXiao wrote:
    > [...] When a user input a date in an input tag yyyy-mm-dd, there is
    > automatically output the inputed date + 7 days, it is like:
    >
    > choose your period: From: <input>________</input> To
    > <input>_______</
    > input>


    The content model of `input' elements is EMPTY.

    HTML: <input ...>
    XHTML: <input ... />

    <http://validator.w3.org/>

    > When a user input 2009-05-17, the <input> after To will automatically
    > output 2009-05-24.
    >
    > I have been doing for hours but still cannot do it.


    No wonder; it is obvious that you are lacking all the basics.

    > Is it must to use Ajax?


    No. In fact, it is pointless to use AJAX for this particular feature.
    (Do you even know what AJAX is?)

    > I read the datepicker sample of Jquery UI, but it can choose
    > one date only.


    jQuery is junk.

    > Are there any way to do it?


    Yes.

    > Any help would be appreciated.


    If you did your homework first it would be appreciated.

    <http://jibbering.com/faq/#posting>


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 17, 2009
    #2
    1. Advertising

  3. In comp.lang.javascript message <>, Sun,
    17 May 2009 18:44:16, Thomas 'PointedEars' Lahn <>
    posted:
    >SamuelXiao wrote:
    >> [...] When a user input a date in an input tag yyyy-mm-dd, there is
    >> automatically output the inputed date + 7 days, it is like:
    >>
    >> choose your period: From: <input>________</input> To
    >> <input>_______</
    >> input>

    >
    >The content model of `input' elements is EMPTY.
    >
    >HTML: <input ...>
    >XHTML: <input ... />



    A typical Lahn reply. To those who truly understand English, it appears
    that The OP, who seems not to have a natural command of English, is
    describing the screen and not the source code. It is common for angle-
    brackets to be used that way, as escaped from natural language.


    The OP should have read the FAQ; earlier versions would have helped.

    This works, but needs refinement :-

    <script>
    function Fn(XX) {
    var D = new Date(XX.replace(/-/g, "/"))
    D.setDate(D.getDate()+7)
    return D.toDateString() }
    </script>

    <form><input type=text name=A onChange="B.value=Fn(A.value)>
    Enter yyyy-mm-dd
    <br><input type=text name=B></form>



    It would be easier with a DATE2 Object :-

    function body : with (new DATE2(XX)) return setXDate(getXDate()+7)
    or, better : return new DATE2(XX).incXDate(7).toString("Y-M-D")

    The date should probably be validated Gregorian, which DATRE2 offers.

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF3 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr J R Stockton, May 17, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    643
    Matthew Speed
    Nov 8, 2003
  2. Chris Berg
    Replies:
    0
    Views:
    844
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,360
    Michael Borgwardt
    May 30, 2004
  4. Matt
    Replies:
    2
    Views:
    563
    Pete Becker
    Nov 8, 2003
  5. palmiere
    Replies:
    1
    Views:
    465
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page