Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

select box population with auto select current date

Posted on 2004-08-12
8
Medium Priority
?
253 Views
Last Modified: 2006-11-17
I have 3 select boxes that are populated with the month, day, and year... Jan Feb Mar, 01,02,03 etc etc

Is there a way to auto select the box closest to today's date?
0
Comment
Question by:Eduski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:thecode101
ID: 11784420
What language are you using?
0
 
LVL 3

Author Comment

by:Eduski
ID: 11784427
coldfusion
0
 
LVL 21

Accepted Solution

by:
pinaldave earned 1000 total points
ID: 11784443
Hi Eduski,

what you can do is this.. .in cold fusion
you go as dateformat(#now()#, "mm") now you get the month...
then after you compare this with your select box month... like
<option value="1">1<cfif mymonth eq "1">selected
<option value="2">2<cfif mymonth eq "2">selected

same goes for year use yy, day use dd
this will work.



Regards,
---Pinal
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 36

Expert Comment

by:Zyloch
ID: 11784493
Hi

It can be done both client-side and server-side depending on how you want it and what you have available. I will only show you client-side Javascript right now, but it's of your opinion how you want to proceed.

<script language="javascript">
<!--

var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function selectClosestDate(monthField,dayField,yearField) {
   //Here, I'm assuming the year field is a input field, not a drop down. If it is, it can be corrected quite easily.
   var now = new Date;
   var currDate = now.getDate()+1;
   var currMonth = monthArray[now.getMonth()];
   var currYear = now.getYear();

   for (var i=0;i<monthField.options.length;i++) {
      if (monthField.options[i].value==currMonth) {
          monthField.selectedIndex = i;
          break;
      }
   }

   for (var i=0;i<dayField.options.length;i++) {
       if (parseInt(dayField.options[i].text,10)==currDate) {
          dayField.selectedIndex = i;
       }
   }

   yearField.value = currYear;
}


Have this function in <body onload> and supply the monthField, dayField, and yearField. For your monthfield, each of the options have to have a value of "January" or "February" like this:

<option value="January">Jan</option>

fully written out. Nothing needs to be done for the date field.

Regards,
Zyloch
0
 
LVL 3

Author Comment

by:Eduski
ID: 11784495
beautiful pinal, thanks
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11784499
Ahh, sorry stale window.

Regards
0
 
LVL 3

Author Comment

by:Eduski
ID: 11784530
thanks for your attempts anyway, i appreciate you taking the time
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 11784740
You are welcome. Glad to help you,
Have a good day!
---Pinal
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question