Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4064366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:50:48+00:00 2026-05-20T15:50:48+00:00

I have a simple webpage that adds & deletes options from a select element

  • 0

I have a simple webpage that adds & deletes options from a select element dynamically. The code works correctly for Chrome & IE, but it fails in Firefox(when I click add nothing happens & the delete button doesn’t even show up?)

What do you think I am doing wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/homepage.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title></title>
    <script LANGUAGE="JavaScript" type = "text/javascript">
    <!--

        function addOption()
        {
            var listbox = document.getElementById( "listbox" );
            var lastIndex = listbox.options.length-1;
            var newOption = document.createElement( "option" );
            newOption.text = "New";
            newOption.value = "New";

            try
            {
                listbox.add( newOption, lastIndex );  // standards compliant; doesn't work in IE  
            }
            catch (ex) 
            { 
                listbox.add( newOption, listbox.selectedIndex ); // IE only 
                alert( "In addOption(): " + ex ); 
            } 

        }

        function deleteOption()
        {
            //alert( "1" );
            var listbox   = document.getElementById( "listbox" );
            var lastIndex = listbox.options.length-1;

            if ( lastIndex < 0 )
                return;

            listbox.remove( lastIndex );
            //alert( "2" );
        }
    -->
    </script>

    <style type="text/css" media="all">
        <!--

            div { text-align: center; }
            button { width: 100px; height: 20px; }
            #listbox { width: 200px; height: 200px;

        -->
    </style>
</head>

<body>

    <div>
        <select id="listbox" multiple="multiple">
            <option>Test</option>
        </select>

        <button value="Add"    onclick="addOption()"/>
        <button value="Delete" onclick="deleteOption()"/>
    </div>

</body>
<!-- InstanceEnd -->
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:50:48+00:00Added an answer on May 20, 2026 at 3:50 pm

    Use:

    <button value="Add"    onclick="addOption()">Add</button>
    <button value="Delete" onclick="deleteOption()">Delete</button>
    

    instead of

    <button value="Add"    onclick="addOption()"/>
    <button value="Delete" onclick="deleteOption()"/>
    

    The button element requires an end tag : http://www.w3.org/TR/html401/interact/forms.html#h-17.5

    Also, use

    listbox.options.add( newOption, lastIndex );
    

    instead of

    listbox.add( newOption, lastIndex );
    

    See here: http://jsfiddle.net/wEFHA/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple webpage that uses the jquery template plugin to dynamically load
I have a simple Web Browser Control that displays a local webpage and that
I have a simple jQuery code that runs on a web page that has
I have a simple webpage that serves as an introduction to a more complex
I have a simple javaFX application that loads a webpage in a WebView componant.
Pretty simple question, I have a webpage that is used exclusively on iPads. I've
I have a mobile webpage that is just a simple form with a submit
I have a very simple accordion in my webpage that I initialise with :
I have simple win service, that executes few tasks periodically. How should I pass
I have simple SSIS package which reads data from flat file and insert into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.