Facebook Twitter Instagram
    Trending
    • Hard Drive Repair After Wrong Voltage Mishap
    • How To Send Excel Workbook As Email Using Button
    • Compare EV Chargers
    • Home Assistant Server Monitoring
    • Mitsubishi Outlander Dash Cam Install
    • Left or Right Pad a String with a VBScript Function
    • List Files in a Folder Using VBScript
    • How to Verify Checksum of a File
    RSS Twitter Instagram Facebook Pinterest YouTube
    Technology Spy
    • Tutorials & Help
    • Reviews
    Technology Spy
    You are at:Home»Development»JavaScript»How To Remove Options From HTML Select Lists Using Javascript
    Coding Programming Guides

    How To Remove Options From HTML Select Lists Using Javascript

    0
    By Matt on April 19, 2013 JavaScript, Tutorials & Help

    When using HTML Select lists it is sometimes useful to be able to remove options from the list dynamically. Perhaps in response to interactions on the page by the user. This is easy to do with JavaScript using the custom function defined below called “SelectOptRemove”.

    It takes two parameters. The first parameter “pValue” is the value of the option your want to remove. The second parameter is pId and that is the ID reference of the Select list you want to deal with.

    function SelectOptRemove(pValue, pId)
    {  
      // SelectOptRemove
      //
      // Removes options from a select list.
      //
      // Takes two arguments.
      //   pValue is the value to remove
      //   pId    is ID of select list
      //
      // Author  : Matt Hawkins
      // Date    : 19/04/2013
      // Website : http://www.how2code.co.uk
    
      var i;
      var vLen;
      var vFlag = false;
      
      // Get select element with ID=pID
      var vList = document.getElementById(pId);
      
      // Get number of options in select list
      vLen = vList.options.length;
    
      // Loop through each option
      for (i=0;i
    

    Here is a link to a simple example HTML page that shows the JavaScript function removing select list options :

    javascript_select_list_remove_option.html

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow To Generate Random Numbers In Python
    Next Article How To Split A List Into Chunks In Python

    Related Posts

    Left or Right Pad a String with a VBScript Function

    List Files in a Folder Using VBScript

    How to Verify Checksum of a File

    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Recent Posts
    November 20, 2022

    Hard Drive Repair After Wrong Voltage Mishap

    March 22, 2022

    How To Send Excel Workbook As Email Using Button

    January 30, 2022

    Compare EV Chargers

    Categories
    • 3D Printing
    • Android
    • Arduino
    • Development
    • ESP8266
    • Excel
    • Gaming
    • General
    • GIMP
    • Home Automation
    • JavaScript
    • Linux
    • Microsoft Office
    • Mobile Devices
    • Oracle APEX
    • Python
    • Raspberry Pi
    • Reviews
    • Security
    • SharePoint
    • Tutorials & Help
    • VBScript
    Tags
    Android APEX Apple Arduino Black Friday csv Elite Dangerous email ESP-01 ESP8266 EV Excel file handling gaming GIMP Gritin Home Assistant Home Automation IMNEED Joystick Linux lists Lumsing Media os.stat os.walk Phishing Power Python Qi Review scam Security select SharePoint 2010 string Syncwire text text files TrueCrypt Ubuntu USB-C VBA VBscript Windows 10
    Web Tools

    A set of quick and basic online tools for web designers and software developers :

    • Hash Generator
    • Text to HTML List
    • Text to HTML Table
    • URL Encoder and Decoder
    • UNIX Timestamp Calculator
    • LED Resistor Calculator
    • Extract Email from Text
    • Mortgage Calculator
    About

    Welcome to Technology Spy, a site devoted to gadgets, computers, programming and all things technology! You’ll also find product reviews for items I own as well as tutorials, guides and scripts for the software I use.

    Archives
    Other Resources
    • MattsBits
    • Raspberry Pi Spy
    Facebook Twitter Instagram Pinterest

    Entries RSS | Comments RSS

    Copyright © 2022 - All Rights Reserved - Matt Hawkins

    mastodon.social@MattHawkins

    Type above and press Enter to search. Press Esc to cancel.