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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:21:06+00:00 2026-06-01T15:21:06+00:00

I am attempting to create a table that will only display one row at

  • 0

I am attempting to create a table that will only display one row at a time and also randomize on each refresh. Here is my code:

<script>
var maxRows = 1; //displays one row at a time
$('#song-list').each(function() {
var cTable = $(this);
var cRows = cTable.find('tr:gt(0)');
var cRowCount = cRows.size();

if (cRowCount < maxRows) {
    return;
}

/* hide all rows above the max initially */
cRows.filter(':gt(' + (maxRows - 1) + ')').hide();

var cPrev = cTable.siblings('.prev');
var cNext = cTable.siblings('.next');

/* start with previous disabled */
cPrev.addClass('disabled');

cPrev.click(function() {
    var cFirstVisible = cRows.index(cRows.filter(':visible'));

    if (cPrev.hasClass('disabled')) {
        return false;
    }

    cRows.hide();
    if (cFirstVisible - maxRows - 1 > 0) {
        cRows.filter(':lt(' + cFirstVisible + '):gt(' + (cFirstVisible - maxRows - 1) +     ')').show();
    } else {
        cRows.filter(':lt(' + cFirstVisible + ')').show();
    }

    if (cFirstVisible - maxRows <= 0) {
        cPrev.addClass('disabled');
    }

    cNext.removeClass('disabled');

    return false;
});

cNext.click(function() {
    var cFirstVisible = cRows.index(cRows.filter(':visible'));

    if (cNext.hasClass('disabled')) {
        return false;
    }

    cRows.hide();
    cRows.filter(':lt(' + (cFirstVisible +2 * maxRows) + '):gt(' + (cFirstVisible +       maxRows - 1) + ')').show();

    if (cFirstVisible + 2 * maxRows >= cRows.size()) {
        cNext.addClass('disabled');
    }

    cPrev.removeClass('disabled');

    return false;
});
});
</script>

Second piece of code:

<script>
Array.prototype.shuffle = function() {
for (var i = 0; i < this.length; i++) {
// Random item in this array.
var r = parseInt(Math.random() * this.length);
var obj = this[r];

// Swap.
this[r] = this[i];
this[i] = obj;
}
}

function randomize(tableID) {
var myTable = document.getElementById(tableID);
var myRows = new Array();
for (i=myTable.rows.length-1; i>=0; i--) {
    var theRow = myTable.rows[i];
    myRows.push(theRow);
    theRow.parentNode.removeChild(theRow);
}
myRows.shuffle();
for (j=0; j<myRows.length; j++) {
    myTable.appendChild(myRows[j]);
}
}
window.onload = function() {
randomize("song-list");
}
//-->
</script>

Both pieces work fine on their own but when I try to combine them the randomize function supersedes the other code and I get a long list of tr that randomize after refresh.

I know there is something I can do to make these codes agree with one another.

Have any suggestions?

  • 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-01T15:21:07+00:00Added an answer on June 1, 2026 at 3:21 pm

    put the whole 1st block of code into a function:

    function showOneRow() {
        ...
    }
    

    and call it after randomize:

    window.onload = function() {
        randomize("song-list");
        showOneRow();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create a MySQL snippet that will analyse a table and
I am attempting to create a new SSRS report that will return and display
I'm attempting to create a table called Students, with only one field, student_name. student_name
So I am attempting to create a search field that will filter contacts on
I have 10 transact SQL scripts that each create a table and fill it
I am attempting to create a template that will utilize data from an Access
I'm attempting to create a small automapper-esq utility that will take a LinqToSql entity
I am attempting to create a table in rails.. I need to be able
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I'm new to database design and I considering implementing something that will be time

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.