tags:

views:

23

answers:

3

Hi guys

Basically I have HTML form which reads in a date from a user, for a hotel booking system.

I have 3 lists, one for day, one for month and one for year.

<SELECT NAME="month">  
 <OPTION VALUE="1"> Jan  
 <OPTION VALUE="2"> Feb  
 <OPTION VALUE="3"> March and so on
</SELECT>

and the same for year(2010 - 2013) and day(1 -31).

Is there any way I can have the default value in the day list set to the current day, the default value in the month list set the the current month, and the default value in the year list set to the current year? Rather than manually having to do it.

Thanks in advance for the help!

A: 

You will have to use javascript. or any client side scripting to do this. I can suggest you some examples but you must first understand the concept of client side scripting

sushil bharwani
I do indeed understand this. I have to be very particular about the way the date is passed through when the user clicks submit, any scripts I have looked at all have the date as one line e.g. 15/07/2010, whereas I need it as 3 seperate items - day, month, year.
James
in javascript we have date object. var d = new Date();which have methods like getDay getYear getMonth they can get you these three things seperately.
sushil bharwani
James, if you look at Gert G's answer, the script he suggests (written in jQuery) merely changes the value of the SELECT elements so the individual name/value pairs will be sent when the form is submitted. In other words, that script (or one that you find and use) only selects values, it does not change the fields in the form (and how they are sent when submitted).
David Lantner
A: 

In response to @sushil bharwani you can also use a server side language if you are comfortable with that. PHP is installed on most web hosts you find now days and a plus (as opposed to javascript) is that it is guaranteed to work. The clients user agent does not matter.

John
I'd rather not get involved with PHP, my resources are pretty limited on the server.
James
Only reason not to have JS is if your target audience is running command line OS.
Thqr
You limit some of your market scope if you use client side technologies like that as your only source. If that fails your website will not function for those that do not have javascript. It is a great language, I use it all the time, but you have to fall back and not make it a priority to use your site.
John
+1  A: 

You will need to use JavaScript. Here's an example, using jQuery:

<script type="text/javascript">
  $(document).ready(function(){
    var CurrentDate=new Date();

    $("#year").val(CurrentDate.getYear());
    $("#month").val(CurrentDate.getMonth());
    $("#day").val(CurrentDate.getDate());
  });
</script>

Here's the code in action.

Gert G