...

View Full Version : Put date in HTML form



jake66
07-31-2011, 09:19 PM
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:


<%=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

VIPStephan
07-31-2011, 10:34 PM
So you’re saying <input type="text" value="<%= date() %>" /> isn’t working?

jake66
08-01-2011, 10:23 AM
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

VIPStephan
08-01-2011, 10:44 AM
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:


<input type="text" value="<?php echo date('m/d/Y'); ?>" />


Look into http://php.net/manual/en/function.date.php for formatting options.

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

vikram1vicky
08-01-2011, 10:51 AM
Using JS you can do.. following is the sample code:



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

}
onload = loadd
</script>

jake66
08-01-2011, 07:46 PM
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:


<input type="text" value="<?php echo date('m/d/Y'); ?>" />


Look into http://php.net/manual/en/function.date.php for formatting options.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum