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

  • Home
  • SEARCH
  • 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 5941553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:07:36+00:00 2026-05-22T16:07:36+00:00

The following function is supposed to remove a selected value from the selectbox, and

  • 0

The following function is supposed to remove a selected value from the selectbox,
and update a hidden field with all values.

I have two problems with it:
Lets say I have the following options in the selectbox : 1071,1000,1052
After removing the first option (1071), the hidden field is getting a value of 1052,1000,1000,

if I remove the second option (1000) the hidden field is 1052,1052,1071
if I remove the third one (1052), I get an options[...].value is null or not an object

Can someone plz help me fix this ?

function removeOptions() {
    var selectbox = document.getElementById('zipcodes');
    var zipcodes = document.getElementById('zip');
    var tmpArray = [];
    var i;
    for (i = selectbox.options.length - 1; i >= 0; i--) {
        if (selectbox.options[i].selected){
            selectbox.remove(i);
        }
        tmpArray.push(selectbox.options[i].value);
    }
    zipcodes.value = tmpArray.join(',');

}
  • 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-22T16:07:36+00:00Added an answer on May 22, 2026 at 4:07 pm

    Assuming you don’t need the selected value in hidden value, place the portion to push in tmpArray in else part

        if (selectbox.options[i].selected){
                    selectbox.remove(i);
        }else{
                tmpArray.push(selectbox.options[i].value);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have the following function on a page that is supposed to be
I have the following jQuery code: <script> function hideMenteeQuestions() { $(#menteeapp).hide(); $(textarea[name='short_term_goals']).rules(remove, required); $(textarea[name='long_term_goals']).rules(remove,
Suppose you have the following function foo . When I'm running a for loop,
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require
Suppose I have the following (shortened for simplicity): jQuery(#grid).jqGrid({ ... ondblClickRow: function() { //
The following function System.Threading.Thread.Sleep(); delay the thread in millisecond, and take the integer value
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
Suppose I have the following HTML: <div class=container> <span class=remove>remove</span> </div> and jquery: $(.container).delegate(.remove,
In this jsFiddle http://jsfiddle.net/littlesandra88/RBU8K/ have I the following code function addRemove(id) { alert(1); $('#'+id).toggle(function()
I have the following function that opens jQuery UI's dialog warning about the delete

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.