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 6320967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:05+00:00 2026-05-24T16:04:05+00:00

I don’t have much experience with javascript so I’ not sure if/how this can

  • 0

I don’t have much experience with javascript so I’ not sure if/how this can be done. So I have a number of select components with a couple of options. One of these options for all of the components is “All”.

Now I need to make sure that no more than one component has “All” selected. I’m using some input fields and making some validations to make sure this condition stands. However I can’t see how I can do the following. When a user selects “All” from a field, and this is not allowed because there is already an “All” on the page, put the previous selection in it’s place.

So far what I have is (component being the current select component):

selectedName = component.options[component.selectedIndex].innerHTML;
if (selectedName == 'All') {
  if (emptyAllSpace() == 1) {
    //here I do all the mumbo jumbo needed and assign to the hidden field the name of 
    //the component
  } 
  else {
    //Here is where I should put back the old selection value. 
  }
 }

Now the else branch is where I need to figure something out. So how can I / how difficult would it be to get the selected option before the currently selected one.

I’m also interested how difficult it would be because I could also go another route and just put as selected the first option that is not ‘All’ but I would rather avoid this if it’s no too time consuming.

Regards,
Bogdan

  • 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-24T16:04:06+00:00Added an answer on May 24, 2026 at 4:04 pm

    Use the onchange event for the select. First store the default value, and reassign it on change. Or use 2 variables which keep the last 2 selected options(?).

    UPDATE

    Use the onfocus to get the value before it changes, http://jsfiddle.net/gQHqj/ .
    In this handler you could register the following onchange, and have that value stored in the closure (onfocus’s scope object).

    UPDATE 2

    I knew something was a bit suspicious, but didn’t have time to inspect, if the user doesn’t move to another element or click somewhere the element is still in focus, and the onfocus will not be called, while onchange will (if the user changes the value), with the wrong prev value. So I came up with a bugfix, you should have this structure : http://jsfiddle.net/gQHqj/4/

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

Sidebar

Related Questions

I don't have much PHP experience and I want to know how to best
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't want to sort the entries. using this does not preserve the order as
Don't know if this has been answered before. Have custom routes to users. If
I don't have any experience in updating a Rails app and when I google
I don't understand where the extra bits are coming from in this article about
I don't remember whether I was dreaming or not but I seem to recall
I don't expect a straightforward silver bullet answer to this, but what are the
I don't know if anyone has seen this issue before but I'm just stumped.
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.