Skip to content

Creating Birth Date Form in Javascript: signup_birthdate.js (part 7)

September 27, 2013

the birth date form is usually made from a drop down selection made of select and option objects. The below example will show how to create option objects in javascript through a for loop. the select object is already created in the html file.

option_months() :: is for creating the month drop down form.

document.getElementById(“month”) :: get the id of the select object

document.createElement(“option”) :: create the option object

option[v].text = months[v] :: set the text attribute of the option object

option[v].value = months[v] :: set the value attribute of the option object

x.add(option[v], null) :: adds the option object created in the loop. null if the option object is positioned at the lowest in the drop down. you can use x.options[0] to position the created option object

  1. function option_months()
  2. {
  3. //++++++++++++++++++++++++++++++++++++++++++
  4. var months = new Array(‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’,
  5. ‘Aug’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’);
  6. var x = document.getElementById(“month”);
  7. var option = new Array();
  8. for (var v = 0; v < months.length; v++) {
  9. option[v] = document.createElement(“option”);
  10. option[v].text = months[v];
  11. option[v].value = months[v];
  12. x.add(option[v], null);
  13. }


below create a option object positioned at the top of the drop down indicated by the x.option[0]. 0 is an index

  1. option[months.length] = document.createElement(“option”);
  2. option[months.length].text = “-Month-“;
  3. option[months.length].value = “0”;
  4. x.add(option[months.length], x.options[0]);
  5. //++++++++++++++++++++++++++++++++++++++++++
  6. }

same algorithm is applied in the days drop down.

  1. function option_days()
  2. {
  3. var x = document.getElementById(“day”);
  4. var option = new Array();
  5. for (var v = 0; v < 31; v++) {
  6. option[v] = document.createElement(“option”);
  7. option[v].text = v + 1;
  8. x.add(option[v], null);
  9. }
  10. option[12] = document.createElement(“option”);
  11. option[12].text = “-day-“;
  12. option[12].value = “0”;
  13. x.add(option[12], x.options[0]);
  14. }

same algorithm is applied in the years drop down.

  1. function option_years()
  2. {
  3. var x = document.getElementById(“year”);
  4. var option = new Array();
  5. for (var v = 0; v < 50; v++) {
  6. option[v] = document.createElement(“option”);
  7. option[v].text = 1963 + v;
  8. x.add(option[v], null);
  9. }
  10. option[50] = document.createElement(“option”);
  11. option[50].text = “-year-“;
  12. option[50].value = “0”;
  13. x.add(option[50], x.options[0]);
  14. }


Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Children's Book Reviews

Malav Shah

official Web Site

My Road to Programming

The journey of how I taught myself to program.


Look at what's brewing up guys! we all are work in progress. So don't meander, lets micromesh everything and have candid conversation about every problem related to C, C++ and JAVA. We can rejuvenate the crinkled faces.


A simple guide to programming...


Information Techonology

Rahul's Work

My Work Tips and Tutorial on Various Tech.

Turnip Farmers

Kingdom Scans


Technology news, trends and analysis covering mobile, big data, cloud, science, energy and media

The Neighborhood

telling the story from every vantage point

HarsH ReaLiTy

A Good Blog is Hard to Find


News About Tech, Money and Innovation


The Diary of a Retiree

50 Year Project

My challenge to visit 192 countries, read 1,001 books, and watch the top 100 movies

[BTW] : Ben Trube, Writer

Writer, Programmer, Singer

My Arch Walkthrough

Arch linux made easy

Don Charisma

because anything is possible with Charisma

SutoCom Solutions

Success & Satisfaction with the Cloud

%d bloggers like this: