Code

DOM Year ComboBox

DOM Method

function displayComboBox(divId) {
// create div
var dv = document.createElement(‘div’);

// create attribute
var attr = document.createAttribute(“id”);
attr.value=”yearPickListDiv”;

// create a text node, add to the div
var tNode = document.createTextNode(“Select a year”);
dv.appendChild(tNode);

// create a select
var selec = document.createElement(“select”);
var opts = document.createElement(“option”);
selec.appendChild(opts);

// loop to add years to options and options to select
for (var i = new Date().getFullYear(); i > 1900; i–) {
var o = document.createElement(“option”);
o.setAttribute(“value”,i);
o.innerHTML=i;
selec.appendChild(o);
}

// add select to div
dv.appendChild(selec);

document.getElementById(“”+divId).appendChild(dv);
}

// on page load, populate the default year values.
displayComboBox(“dvOne”);

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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