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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:17+00:00 2026-05-12T10:16:17+00:00

I have the jquery code below that returns a list of ID’s like this

  • 0

I have the jquery code below that returns a list of ID’s like this 1|2|3|4|5|6|7|8|9 and so on for every List item I have on the page, I also have a dropdown selection box named topfriendNumber. I need to take the value from topfriendNumber dropdown box and make sure my list of IDs does not exceed it.

So if the dropdown is selected as 4 then it should only allow 4 numbers 1|2|3|4

Based on this code below can you help?

This could probably be added into the bottom part where it is already using the number from the dropdown box

<select name="topfriendNumber" id="topfriendNumber">
    <option value="3">3</option>
    <option value="6" selected="selected">6</option>
    <option value="9">9</option>
    <option value="12">12</option>
</select>

<script>
    function saveOrder() {
        var serialStr = "";
        $("#topfriends li").each(function (i, elm) {
            serialStr += (i > 0 ? "|" : "") + $(elm).attr("friendID");
        });
        // alert(serialStr);   //1|2|3|4|5|6|7|8|9
        $('select[name=topfriendNumber]').change();
        $.ajax({
            url: "exampe.php/SaveListOrder",
            data: '{"ids":"' + serialStr + '"}',
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8"
        });
    };

    //changes the background colors depending on the amount selected from the dropdown list
    $('select[name=topfriendNumber]').change(function () {
        var val = $(this).val();
        //reset style
        $('ul#topfriends > li').css("background-color", "");
        //apply to all LIs before value of select
        $('ul#topfriends > li:lt(' + val + ')').css("background-color", "red");
    }).change();
</script>
  • 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-12T10:16:17+00:00Added an answer on May 12, 2026 at 10:16 am

    Why not stop short of that, and not even generate the list beyond what you need?

    var needed = $('select[name=topfriendNumber]').val();
    $("#topfriends li").each(function (i, elm) {
        serialStr += (i > 0 ? "|" : "") + $(elm).attr("friendID");
        if (i > needed) {
            return false;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that shows 3 drop-down selectors on the page. I also
Please see the below code: I am have a table row defined using asp.net
I have an ASP.NET MVC page that has left Menu Navigation that is built
I have a list of information around 30-50 rows each one requiring their own
I have a partial view that has a number of Div's, each are set
I am trying to create a jQuery content slider that will stop when a
I apologize in advanced if this question is too broad. In fact it's 4
I have a little trouble understanding the security bit around JSON, because often things
My goal is to submit a form in a Colorbox modal via ajax (that
Following on from a previous question, ( previous question here ), the problem I'm

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.