Java Script-Date in textfield

Discussion in 'Web Design, HTML And CSS' started by vkwd7, May 15, 2010.

  1. vkwd7

    vkwd7 New Member

    Joined:
    May 15, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    thanks and good wishes to all members from a novice!
    I am making a calculator in Java script where in a date is entered by user in the textbox in a form.I want that this date should be used in the progam.eg. the user types say 25-4-2000 . and if the date lies between 13-11-2002 to 1-11-2003, his ' var Da' is 26 and else it is 36.
    I have written the following code but donot know how to proceed further.Please help.
    is it possible to determine which date is greater amongst the two without using the parse method.ie. how to find out whether date entered by user is > or < than the date 1-11-2003?
    HTML:
    <script type="text/javascript">
    function Pension(form)
    {
    var dt1=form.dor.value;
    dt1=Date.parse(dt1);
    dt2=new Date ('13-11-2002');
    dt2=Date.parse(dt2);
    var DA=0;
    if ( (dt1) <= (dt2))
    {
    DA=26;
    form.da.value=DA;
    }
     
    }
     
    <!-- done hiding from old browsers -->
    </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="">
    <p>
    <input type="text" name="dor" id="textfield" /> 
    DOR </p>
    <p>
    <input type="text" name="da" readonly size="10" />
    DA</p>
    <p>
    <input type="text" name="bp" id="textfield3" />
    BP</p>
    <p>
    <input type="button" name="cal" id="cal" value="calculate" onclick=Pension(this.form) />
    </p>
    </form>
    </body>
    </html>
     
    Last edited by a moderator: May 16, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice