Hi all
i have shuffle function with me which shuffles data in an array and i am displaying the array values in a table along column wise.By an on click event the values in the table has to be shuffled and again they have to be displayed in the table.
shuffle function code is here -
function shuffle()
-
{
-
-
-
-
var randomNumber;
-
-
var len=this.length-1;
-
-
randomNumber = Math.floor(Math.random()*len);
-
// document.write(randomNumber);
-
-
-
if(randomNumber > len)
-
{
-
randomNumber =len;
-
}
-
-
-
for(var i =0; i <= randomNumber; i++)
-
{
-
-
-
-
if(i !=len)
-
{
-
this[i] = this[i+1];
-
}
-
else
-
{
-
temp =this[i];
-
-
this[i]=this[0];
-
-
this[0]=temp ;
-
}
-
-
-
-
}
-
-
}
-
and i have used this shuffle function as below -
function autoSpin()
-
{
-
-
//var Date.monthNames = new Array('Active','Passive','Bargain','Vegas','Value');
-
-
months.shuffle();
-
-
var shuffleresults= Date.monthNames.join("br<>");
-
var len = shuffleresults.rows.length, i;
-
if(shuffleresults.rows.length > 0) {
-
alert("hi");
-
-
Date.monthNames[0] = shuffleresults.rows.item[0].Date.monthNames[0];
-
Date.monthNames[1] = shuffleresults.rows.item[1].Date.monthNames[1];
-
Date.monthNames[2] = shuffleresults.rows.item[2].Date.monthNames[2];
-
Date.monthNames[3] = shuffleresults.rows.item[3].Date.monthNames[3];
-
Date.monthNames[4] = shuffleresults.rows.item[4].Date.monthNames[4];
-
-
//spinnerId = shuffleresults.rows.item[0].spinnerId;
-
-
-
}
-
document.getElementById('Date.monthNames[0]').innerHTML = Date.monthNames[0];
-
document.getElementById('Date.monthNames[1]').innerHTML = Date.monthNames[1];
-
document.getElementById('Date.monthNames[2]').innerHTML = Date.monthNames[2];
-
document.getElementById('Date.monthNames[3]').innerHTML = Date.monthNames[3];
-
document.getElementById('Date.monthNames[4]').innerHTML = Date.monthNames[4];
-
-
-
Date.dayNames.shuffle();
-
//var Date.dayNames=new Array('LEAPS','Earnings','Economic','Weekly','Daily');
-
-
var shuffleresults1= Date.dayNames.join("<br>");
-
var len = shuffleresults1.columns.length, i;
-
if(shuffleresults1.columns.length > 0) {
-
-
-
Date.dayNames[0] = shuffleresults1.columns.item[0].Date.dayNames[0];
-
Date.dayNames[1] = shuffleresults1.columns.item[1].Date.dayNames[1];
-
Date.dayNames[2] = shuffleresults1.columns.item[2].Date.dayNames[2];
-
Date.dayNames[3] = shuffleresults1.columns.item[3].Date.dayNames[3];
-
Date.dayNames[4] = shuffleresults1.columns.item[4].Date.dayNames[4];
-
}
-
//spinnerId = shuffleresults1.columns.item[0].spinnerId;
-
-
-
-
document.getElementById('Date.dayNames[0]').innerHTML = Date.dayNames[0];
-
document.getElementById('Date.dayNames[1]').innerHTML = Date.dayNames[1];
-
document.getElementById('Date.dayNames[2]').innerHTML = Date.dayNames[2];
-
document.getElementById('Date.dayNames[3]').innerHTML = Date.dayNames[3];
-
document.getElementById('Date.dayNames[4]').innerHTML = Date.dayNames[4];
-
-
-
-
//var Date.yearNames=new Array('2$','1$','50 cents','25 cents','5 cents');
-
Date.yearNames.shuffle();
-
-
var shuffleresults2= Date.yearNames.join("<br>");
-
var len = shuffleresults2.columns.length, i;
-
if(shuffleresults2.columns.length > 0) {
-
-
-
Date.yearNames[0] = shuffleresults2.columns.item[0].Date.yearNames[0];
-
Date.yearNames[1] = shuffleresults2.columns.item[1].Date.yearNames[1];
-
Date.yearNames[2] = shuffleresults2.columns.item[2].Date.yearNames[2];
-
Date.yearNames[3] = shuffleresults2.columns.item[3].Date.yearNames[3];
-
Date.yearNames[4] = shuffleresults2.columns.item[4].Date.yearNames[4];
-
-
//spinnerId = shuffleresults2.rows.item[0].spinnerId;
-
-
-
}
-
document.getElementById('Date.yearNames[0]').innerHTML = Date.yearNames[0];
-
document.getElementById('Date.yearNames[1]').innerHTML = Date.yearNames[1];
-
document.getElementById('Date.yearNames[2]').innerHTML = Date.yearNames[2];
-
document.getElementById('Date.yearNames[3]').innerHTML = Date.yearNames[3];
-
document.getElementById('Date.yearNames[4]').innerHTML = Date.yearNames[4];
-
-
}
-
for reference please visit the url http://www.urbanspoon.com/spin-widget
for the spin button in that application i have used an on click event with function autoSpin() and i have defined the function above.The arrays displayed here are
Date.monthNames,Date.dayNames,Date.yearNames please check this one and if you find any errors please revert back to me
Thanks in advance
2 1551
Firstly, check the error console. What errors do you see?
Do you have a page with the code in action?
i have a code for single array to shuffle here it is -
<html>
-
<head>
-
<title>How to shuffle an array in JavaScript</title>
-
<script language="JavaScript">
-
-
Array.prototype.shuffle = shuffle;
-
-
function shuffle()
-
{
-
-
var tempSlot;
-
-
var randomNumber;
-
-
-
for(var i =0; i != this.length; i++)
-
{
-
-
randomNumber = Math.floor(Math.random() * this.length);
-
-
tempSlot = this[i];
-
-
this[i] = this[randomNumber];
-
-
this[randomNumber] = tempSlot;
-
-
-
-
}
-
-
}
-
-
function shuffleNumbers()
-
{
-
-
var numbers = new Array('Active','Passive','Bargain','Vegas','value');
-
-
numbers.shuffle();
-
-
var numbersAfterShuffle = numbers.join("<br>");
-
-
document.getElementById("result").innerHTML = numbersAfterShuffle;
-
-
-
}
-
-
</script>
-
</head>
-
-
<body onload="javascript:shuffleNumbers();">
-
-
<div id="result"></div>
-
-
<input type='button' onclick='shuffleNumbers()' value='Shuffle'/>
-
-
</body>
-
</html>
-
and i applied the same logic to all the three rows in my application.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jon Haakon |
last post by:
Hi,
I'm developing a websolution using ASP and DHTML technology that's
running on a MS IIS webserver.
My solution is frame based with a toolbar on top, a hidden frame for
scripts in the...
|
by: JN |
last post by:
I would like to disable all links and buttons on HTML page to prevent
multiple clicking while page is not yet sent to server. I tried to
disable whole document, but this won't prevent links to be...
|
by: Moist |
last post by:
Hi,
I have an embedded HTML object as follows (ignore the code tag):
<code>
<object id="page" data="table.html" type="text/html" .... >
</code>
I look for the Javascript code (placed in...
|
by: mukeshgupta.WD |
last post by:
i am developing a website in which i want to call a html page load into
a div tag dynamically followed by link. i want to change the html page
every time when a link is clicked.
can any body have...
|
by: DH |
last post by:
Hi,
I'm trying to strip the html and other useless junk from a html page..
Id like to create something like an automated text editor, where it
takes the keywords from a txt file and removes them...
|
by: William Krick |
last post by:
I know that you can use the javascript document.write() method to
inject new content into a page.
Is it possible to _modify_ an HTML page?
For example, say I wanted to go through the current...
|
by: Jeff |
last post by:
I asked this question sometime ago. some help was given, but A.) i didn't
understand the help and B.) I can't find the post.
i am looking for a way to take a table of stats on an HTML page, and...
|
by: Mariusf |
last post by:
I am a novice Perl programmer and need to change a perl script that I use to create web pages with thumbnail images and some text. Currently the script created a web page for each artist / category...
|
by: thig95 |
last post by:
I have an embedded html page loaded via the object tag on my main page. I'm working in XHTML strict so using iFrame is out. I call the embedded page using this:
<object data="mypage.html"...
|
by: malcster2 |
last post by:
hello, i am a beginner to ajax.
i have created a mysql database, which i would like to access from a web page.
i have created 3 files, a html to display the data, a php file to extract the data,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |