Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Put date in HTML form

    Hi,

    I am trying to create a form with a number of different fields, one of which I want to be called 'date'.

    I want the field to display the current date by default, but for the end user to be able to change the date if they wish.

    I have done some searches and found that I can do this using some very simple ASP:

    Code:
    <%=date()%>

    This works fine on its own, but I cannot make it work as a default value for the field?

    Any help is much appreciated,
    jake66

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,797
    Thanks
    6
    Thanked 1,023 Times in 996 Posts
    So you’re saying <input type="text" value="<%= date() %>" /> isn’t working?

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    So you’re saying <input type="text" value="<%= date() %>" /> isn’t working?
    Hi,
    Thanks for your reply,
    I am sure the code does and would work, but I have just found out that my hosting server does not support ASP.....

    Can I get the same effect using any other coding language?

    Thanks.
    jake66

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,797
    Thanks
    6
    Thanked 1,023 Times in 996 Posts
    Haha, you’re funny. :-) How did you get the idea to use ASP anyway then? Did you just choose it randomly?

    What languages does your server support? First thing that comes to my mind would be PHP. Try this:
    PHP Code:
    <input type="text" value="<?php echo date('m/d/Y'); ?>" />
    Look into http://php.net/manual/en/function.date.php for formatting options.

    Edit: Oh and mind you to save the file as PHP file (.php extension).
    Last edited by VIPStephan; 08-01-2011 at 10:53 AM.

  • Users who have thanked VIPStephan for this post:

    jake66 (08-01-2011)

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    Using JS you can do.. following is the sample code:

    Code:
     <input type="text" value="" id="sd" />
     <script type="text/javascript">
    function loadd()
    {
        document.getElementById("sd").value= (Date());
        
    }
    onload = loadd
    </script>

  • #6
    New Coder
    Join Date
    Jul 2011
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    Haha, you’re funny. :-) How did you get the idea to use ASP anyway then? Did you just choose it randomly?

    What languages does your server support? First thing that comes to my mind would be PHP. Try this:
    PHP Code:
    <input type="text" value="<?php echo date('m/d/Y'); ?>" />
    Look into http://php.net/manual/en/function.date.php for formatting options.

    Edit: Oh and mind you to save the file as PHP file (.php extension).

    Yes you've probally figured that I'm not too good at this kind of thing!!

    Thanks very much, this works like a charm


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •