473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change data on html page?

4 New Member
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
Expand|Select|Wrap|Line Numbers
  1. function shuffle()
  2. {
  3.  
  4.  
  5.  
  6.       var randomNumber;
  7.  
  8.       var len=this.length-1;
  9.  
  10.       randomNumber = Math.floor(Math.random()*len);
  11.      // document.write(randomNumber);
  12.  
  13.  
  14.       if(randomNumber > len)
  15.                 {
  16.                 randomNumber =len;
  17.                 }
  18.  
  19.  
  20.       for(var i =0; i <= randomNumber; i++)
  21.       {
  22.  
  23.  
  24.  
  25.             if(i !=len)
  26.                    {
  27.             this[i] = this[i+1];
  28.                      }
  29.           else
  30.           {
  31.           temp =this[i];
  32.  
  33.           this[i]=this[0];
  34.  
  35.           this[0]=temp ;
  36.           }
  37.  
  38.  
  39.  
  40.       }
  41.  
  42. }
  43.  
and i have used this shuffle function as below
Expand|Select|Wrap|Line Numbers
  1. function autoSpin()
  2. {
  3.  
  4.      //var Date.monthNames = new Array('Active','Passive','Bargain','Vegas','Value');
  5.  
  6.     months.shuffle();
  7.  
  8.      var shuffleresults= Date.monthNames.join("br<>");
  9.      var len = shuffleresults.rows.length, i;
  10.             if(shuffleresults.rows.length > 0) {
  11.                 alert("hi");
  12.  
  13.                 Date.monthNames[0] = shuffleresults.rows.item[0].Date.monthNames[0];
  14.                 Date.monthNames[1] = shuffleresults.rows.item[1].Date.monthNames[1];
  15.                 Date.monthNames[2] = shuffleresults.rows.item[2].Date.monthNames[2];
  16.                 Date.monthNames[3] = shuffleresults.rows.item[3].Date.monthNames[3];
  17.                 Date.monthNames[4] = shuffleresults.rows.item[4].Date.monthNames[4];
  18.  
  19.                 //spinnerId = shuffleresults.rows.item[0].spinnerId;
  20.  
  21.  
  22.              }    
  23.             document.getElementById('Date.monthNames[0]').innerHTML = Date.monthNames[0];
  24.             document.getElementById('Date.monthNames[1]').innerHTML = Date.monthNames[1];
  25.             document.getElementById('Date.monthNames[2]').innerHTML = Date.monthNames[2];
  26.             document.getElementById('Date.monthNames[3]').innerHTML = Date.monthNames[3];
  27.             document.getElementById('Date.monthNames[4]').innerHTML = Date.monthNames[4];
  28.  
  29.  
  30.       Date.dayNames.shuffle(); 
  31.       //var Date.dayNames=new Array('LEAPS','Earnings','Economic','Weekly','Daily');
  32.  
  33.      var shuffleresults1= Date.dayNames.join("<br>");
  34.      var len = shuffleresults1.columns.length, i;
  35.             if(shuffleresults1.columns.length > 0) {
  36.  
  37.  
  38.                 Date.dayNames[0] = shuffleresults1.columns.item[0].Date.dayNames[0];
  39.                 Date.dayNames[1] = shuffleresults1.columns.item[1].Date.dayNames[1];
  40.                 Date.dayNames[2] = shuffleresults1.columns.item[2].Date.dayNames[2];
  41.                 Date.dayNames[3] = shuffleresults1.columns.item[3].Date.dayNames[3];
  42.                 Date.dayNames[4] = shuffleresults1.columns.item[4].Date.dayNames[4];
  43.             }
  44.                 //spinnerId = shuffleresults1.columns.item[0].spinnerId;
  45.  
  46.  
  47.  
  48.             document.getElementById('Date.dayNames[0]').innerHTML = Date.dayNames[0];
  49.             document.getElementById('Date.dayNames[1]').innerHTML = Date.dayNames[1];
  50.             document.getElementById('Date.dayNames[2]').innerHTML = Date.dayNames[2];
  51.             document.getElementById('Date.dayNames[3]').innerHTML = Date.dayNames[3];
  52.             document.getElementById('Date.dayNames[4]').innerHTML = Date.dayNames[4];
  53.  
  54.  
  55.  
  56. //var Date.yearNames=new Array('2$','1$','50 cents','25 cents','5 cents');      
  57. Date.yearNames.shuffle();
  58.  
  59.      var shuffleresults2= Date.yearNames.join("<br>");
  60.      var len = shuffleresults2.columns.length, i;
  61.             if(shuffleresults2.columns.length > 0) {
  62.  
  63.  
  64.                 Date.yearNames[0] = shuffleresults2.columns.item[0].Date.yearNames[0];
  65.                 Date.yearNames[1] = shuffleresults2.columns.item[1].Date.yearNames[1];
  66.                 Date.yearNames[2] = shuffleresults2.columns.item[2].Date.yearNames[2];
  67.                 Date.yearNames[3] = shuffleresults2.columns.item[3].Date.yearNames[3];
  68.                 Date.yearNames[4] = shuffleresults2.columns.item[4].Date.yearNames[4];
  69.  
  70.                 //spinnerId = shuffleresults2.rows.item[0].spinnerId;
  71.  
  72.  
  73.             }            
  74.             document.getElementById('Date.yearNames[0]').innerHTML = Date.yearNames[0];
  75.             document.getElementById('Date.yearNames[1]').innerHTML = Date.yearNames[1];
  76.             document.getElementById('Date.yearNames[2]').innerHTML = Date.yearNames[2];
  77.             document.getElementById('Date.yearNames[3]').innerHTML = Date.yearNames[3];
  78.             document.getElementById('Date.yearNames[4]').innerHTML = Date.yearNames[4];
  79.  
  80.  
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
Oct 13 '10 #1
2 1555
acoder
16,027 Recognized Expert Moderator MVP
Firstly, check the error console. What errors do you see?

Do you have a page with the code in action?
Oct 14 '10 #2
thimmappa
4 New Member
i have a code for single array to shuffle here it is
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>How to shuffle an array in JavaScript</title>
  4. <script language="JavaScript">
  5.  
  6. Array.prototype.shuffle = shuffle;
  7.  
  8. function shuffle()
  9. {
  10.  
  11.       var tempSlot;
  12.  
  13.       var randomNumber;
  14.  
  15.  
  16.       for(var i =0; i != this.length; i++)
  17.       {
  18.  
  19.             randomNumber = Math.floor(Math.random() * this.length);
  20.  
  21.             tempSlot = this[i];
  22.  
  23.             this[i] = this[randomNumber];
  24.  
  25.             this[randomNumber] = tempSlot;
  26.  
  27.  
  28.  
  29.       }
  30.  
  31. }
  32.  
  33. function shuffleNumbers()
  34. {
  35.  
  36.       var numbers = new Array('Active','Passive','Bargain','Vegas','value');
  37.  
  38.       numbers.shuffle();
  39.  
  40.       var numbersAfterShuffle = numbers.join("<br>");
  41.  
  42.       document.getElementById("result").innerHTML = numbersAfterShuffle;
  43.  
  44.  
  45. }
  46.  
  47. </script>
  48. </head>
  49.  
  50. <body onload="javascript:shuffleNumbers();">
  51.  
  52. <div id="result"></div>
  53.  
  54. <input type='button' onclick='shuffleNumbers()' value='Shuffle'/>
  55.  
  56. </body>
  57. </html>
  58.  
and i applied the same logic to all the three rows in my application.
Oct 14 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2317
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 middel (all actions run here), and on bottom html pages will be shown. The bottom page contains forms witch is developed with a 3ed party design tool from Acrobat and stored as HTML. It wouldn't be any problem storing these files as html. But the main...
3
6540
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 clicked on. Any ideas how to do that? Thanks.
6
2310
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 the main document) that can reload or refresh the object contains at will?
3
11442
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 idea, please help!!!!!!!!!!
13
4174
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 from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
3
1758
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 page and change every <B></B to <I></I>? Is this possible? If so, how?
8
1837
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 turn the data into variables, and upload to a DB using ASP. say if a page contained stats from a golf tournament, i would be able to pull the data and insert it into a db table on MY server. can someone help me with this??
7
3378
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 with all the thumb images below one another in the table. Thus the table has one column with a row for each image. I am trying to change the script to have 3 columns in the table in the end (first testing with second column as in the attached...
4
3371
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" type="text/html"></object> Now the referenced page loads just fine in the browsers I am testing with (IE 6&7/FF/ Safari). My problem is I have a simpe link on the embedded page that when clicked should change the main page to whatever URL the link points...
2
2239
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, and a javascript file to to the clever stuff. when i access the html page, all the data is displayed correcty, but if i add or delete any records, and press the button i have created to refresh the data(without reloading), the data doesn't change....
0
8392
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.