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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:36:13+00:00 2026-06-12T14:36:13+00:00

<select id=edit-attributes-1> <option value=44 selected=selected>0</option> <option value=35>1</option> <option value=36>2</option> <option value=37>3</option> </select> <select id=edit-attributes-2>

  • 0
<select id="edit-attributes-1">
      <option value="44" selected="selected">0</option>
      <option value="35">1</option>
      <option value="36">2</option>
      <option value="37">3</option>
</select>
<select id="edit-attributes-2">
      <option value="44" selected="selected">0</option>
      <option value="35">1</option>
      <option value="36">2</option>
      <option value="37">3</option>
</select>
<select id="edit-attributes-3">
      <option value="44" selected="selected">0</option>
      <option value="35">1</option>
      <option value="36">2</option>
      <option value="37">3</option>
</select>
<select id="edit-attributes-4">
      <option value="44" selected="selected">0</option>
      <option value="35">1</option>
      <option value="36">2</option>
      <option value="37">3</option>

</select>
    <select id="edit-attributes-9" name="attributes[9]" class="form-select">
      <option value="44" selected="selected">0</option>
      <option value="35">1</option>
      <option value="36">2</option>
      <option value="37">3</option>
    </select>

       <select id="edit-attributes-11" name="attributes[11]" class="form-select">
      <option value="45" selected="selected">0</option>
      <option value="39">1</option>
      <option value="41">2</option>

    </select>

​

//This Code adds <span>+</span> and <span>-</span> with their attributes
$('select[id^="edit-attributes-"][id!="edit-attributes-12"]').after(function() {
    var count = $(this).find('option').length;
    return '<span class="step stepup step-' + this.id + '" id="step-up-' + this.id.substring(16) + '">+</span><span class="step stepdown step-' + this.id + '" id="step-down-' + this.id.substring(16) + '">-</span>';

});

//This code detects reacts when + or - is clicked.
$('span[id^="step-"]').click(function() {
    //Tokenized class name into array <span class="step stepup step-edit-attributes-1" id="step-up-1">+</span> 
    var classList = $(this).attr('class').split(/\s+/); 
    //Use for Option Index = 0 ofcourse
    var min = 0;
    //Use for Option Index Max = number of options in particular Select
    var max = $("#" + classList[2].substring(5) + " option").length;
    //Index of selected Option
    var selected = $("#" + classList[2].substring(5) + " option:selected").index();
    //Value of Selected Option
    var value = $("#" + classList[2].substring(5) + " option:selected").val();

    //since id is "step-up-ID" just want to get the UP or DOWN
    var op = this.id.split("-");


    if (op[1] == "up") { // second token of op = up or down

        if (value < max) {
            value++;
            alert(selected + ":" + value + " : " + op[1]);            
            //remove any selected option ??????
//MY PROBLEM IS HERE WHEN I TRY TO REMOVE EXISTING SELECTED AND SELECT A NEW OPTION AFTER THE SELECTED ONE**

            $("#" + classList[2].substring(5) + " option:selected").removeAttr("selected");
            //assign new selected option ???????
            $("#" + classList[2].substring(5) + " option").selectedIndex=value;
        }
    }
    if (op[1] == "down") {
        if (value > min) {            
            value--;
            alert(selected + ":" + value + " : " + op[1]);
//MY PROBLEM IS HERE WHEN I TRY TO REMOVE EXISTING SELECTED AND SELECT A NEW OPTION BEFORE THE SELECTED ONE**
            $("#" + classList[2].substring(5) + " option:selected").removeAttr("selected");
            $("#" + classList[2].substring(5) + " option").selectedIndex=value;
        }

    }
});​

My goal is here when I click (-) it will change selected 1 step above, then (+) select new option one stop below. Can someone help out and maybe optimized this code. I’ve been trying to swim on this for hours already.

  • 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-06-12T14:36:15+00:00Added an answer on June 12, 2026 at 2:36 pm

    Here’s the working version + optimised of your script.

    //This code detects reacts when + or - is clicked.
    $('span[id^="step-"]').click(function() {
        //Tokenized class name into array <span class="step stepup step-edit-attributes-1" id="step-up-1">+</span> 
        var classList = $(this).attr('class').split(/\s+/),
            item      = $('#'+classList[2].substring(5)),
            selected  = item[0].selectedIndex;
    
        //since id is "step-up-ID" just want to get the UP or DOWN
        var op = this.id.split("-");
    
        var index = (op[1] == 'up' ? 1 : -1) + selected;
        if (item.find('option')[index]) {
            item[0].selectedIndex = index;
        }    
    });​
    

    http://jsfiddle.net/rezigned/qjVHM/15/

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

Sidebar

Related Questions

Say I have a HTML form containing this select element: <select name=mySelect id=mySelect> <option
HTML <select id=edit-attributes-1></select> <select id=edit-attributes-2></select> <select id=edit-attributes-3></select> <select id=edit-attributes-4></select> This is generated by a
The select lists are not rendering with the correct option selected. I've tried this
consider both types: <select name=garden> <option>Flowers</option> <option selected=selected>Shrubs</option> <option>Trees</option> <option selected=selected>Bushes</option> <option>Grass</option> <option>Dirt</option> </select>
So i have this: <select name=study_year> <option>Year I</option> <option>Year II</option> <option>Year III</option> </select> I
SELECT works, Edit button works, but after editing, when I press Save the Grid
EDIT: My mistake was that I had a go after the first select statement
EDIT: This question is about finding definitive reference to MySQL syntax on SELECT modifying
I need the text value of selected options in a multiple select returned as
i am trying to edit a select list every time the list before it

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.