Categories
JavaScript jQuery Solutions Web

JavaScript Loop Through Select Options – Example

Update (2026): This guide has been updated with modern ES6+ methods and troubleshooting FAQs to ensure it works with the latest web standards and frameworks.

Iterating through dropdown (select) options is a fundamental task in web development. Whether you are validating a form, dynamically filtering data, or syncing UI states, knowing how to efficiently loop through a <select> element’s options is essential for a smooth user experience.

In this guide, we will cover the modern ES6+ way, the traditional approach, and the jQuery method.

1. Modern JavaScript (ES6+) — Recommended

The most efficient and readable way to handle this today is by converting the HTMLOptionsCollection into an array and using the forEach method. This is the standard in modern frameworks like React, Vue, or Vanilla JS projects.

JavaScript

// Get the dropdown by ID
const dropdown = document.getElementById("dropdownlist");

// Convert options to an Array and iterate
Array.from(dropdown.options).forEach((option) => {
    console.log("Text:", option.text, "Value:", option.value);
    
    // Add your custom logic or operations here
});

2. The Traditional JavaScript Loop

If you need to support legacy browsers (like very old versions of IE) or prefer the standard for loop, use the code below. It is highly performant as it avoids creating an array copy.

JavaScript

var x = document.getElementById("dropdownlist");

for (var i = 0; i < x.options.length; i++) {
    console.log("Value: " + x.options[i].value);
    
    // Perform operations based on each option
}

3. The jQuery Approach

If your project is already utilizing the jQuery library, the .each() method provides a very concise and readable syntax for targeting child options.

JavaScript

$("#dropdownlist > option").each(function() {
    console.log("Text: " + this.text + " | Value: " + this.value);
    
    // Add your operations here
});

Comparison Table: Which Method Should You Use?

MethodBest ForComplexity
ES6 Array.from()Modern Web Apps / Clean CodeLow
Standard for loopHigh Performance / Legacy SupportMedium
jQuery .each()Projects already using jQueryLow

Frequently Asked Questions (FAQs)

How do I select a specific value while iterating?
You can add a simple conditional check inside your loop. For example: if (option.value === "target") { option.selected = true; }

How do I get the total count of options in a dropdown?
You can simply access the length property: document.getElementById("dropdownlist").options.length;

Can I iterate through a dropdown without using an ID?
Yes, you can use document.querySelector('select') or document.getElementsByClassName('your-class') to target the element without an ID.

Categories
Android Nexus 5

Turn Off Keyboard Vibration in Android Lollipop

Google Keyboard is the default keyboard in Android 5, Lollipop. By default, its configured to enable vibration on key press. If you are someone who dislikes this feature, here is a simple way to turn off keyboard vibration in it:

Steps to Disable or Turn Off Keyboard Vibration:

  • Go to Home -> Settings -> Language & input
  • Locate “Google Keyboard” (under Keyboard & input methods) and tap it
  • Tap on Preferences
  • Turn off the “Vibrate on keypress” option

UPDATE: For Android 6 (Marsh Mallow) use these steps

Categories
Android Apps FaceBook Solutions Web

How to Disable Facebook Links from opening in the Facebook App Browser

Facebook logo Español: Logotipo de Facebook Fr...Facebook recently update added a new feature to its mobile app. The feature loads all links clicked on Facebook to open in the in-app browser as opposed to a browser installed on the phone. While this is faster, it seriously limits what you can do with the open page (for eg. sharing is limited). But fortunately this feature can be disabled.

To disable it, do the following:

  1. In the Facebook app, goto Menu > App Settings
  2. In General Settings, you will find the “Always open links with external browser” option. Tap it to Enable it.
  3. Now your facebook app should behave just the way it did before the update.

Screenshots:
_20141117_204056 _20141117_204038

Categories
Internet Explorer Solutions Web

How to force Internet Explorer to view a page in a specific version mode.

Internet Explorer 7
Internet Explorer 7 (Photo credit: Wikipedia)

Meta tags can be used to force Internet Explorer(IE) browser to use a specific standards mode. The X-UA-Compatible meta tag tells IE what view mode to use to render the current page.

Here is how to emulate different browser modes using meta tags:

Emulate IE 7:

<meta http-equiv="X-UA-Compatible" content="IE=7">

Emulate IE 8:

<meta http-equiv="X-UA-Compatible" content="IE=8">

Emulate IE 9:

<meta http-equiv="X-UA-Compatible" content="IE=9">

If the end client visits the page on a browser that is older than the specifed view mode (eg. User has IE 8 but view mode forces IE 9), the browser will ignore the meta tag and render the page the best way it can.

Categories
FaceBook Solutions Web

FaceBook Places Map – How to add places visited to your Facebook Map

Facebook logo Español: Logotipo de Facebook Fr...
Facebook logo (Photo credit: Wikipedia)

In your Facebook Profile’s “About” section there is a map of places you have visited or lived. You can add places to this section by adding a “Places” post to your Timeline. Here is how to do that:

  1. In your Timeline, click on “More” under your cover photo
  2. Select “Places”
  3. Click on “Add Places”
  4. Enter the name of the of the place you want to add
  5. Select the type of post you want to share (eg. Visited, Lived etc.)
  6. Fill the relavant details of the post and click “Post”

Note: These posts that you add to your map, will also appear in your Timeline.