![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? |
#3
| |||
| |||
|
|
Dear All, I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? |
#4
| |||
| |||
|
|
I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? |

|
waiting for reply |
#5
| |||
| |||
|
|
sanju wrote: I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? Quick hack: * /** * ** @return A pseudo-random IEEE-754 double in the interval * ** * <tt>[0, 1)</tt>. * ** @type number * **/ * function prng() * { * * var r = Math.random(); * * // Opera bug workaround * * if (r == 1) r = 0; * * return r; * } * /** * ** Returns a pseudo-random integer value in the interval * ** <tt>[0, top)</tt>, or in the interval <tt>[bottom, top)</tt * ** if <code>bottom</code> was provided. * ** * ** @param top : number * ** @param bottom : optional number * ** @return pseudo-random integer value in the specified interval * ** @type number * **/ * function prng_int(top, bottom) * { * * if (!bottom) bottom = 0; * * return Math.floor(prng() * (top - bottom)) + bottom; * } * /** * ** Sorts the rows of the first table body of the document randomly. * **/ * function bodyLoad() * { * * // get table object reference * * var t = ... * * if (t) * * { * * * // get table body object reference * * * var tbody = (t.tBodies || [])[0]; * * * if (tbody) * * * { * * * * for (var rows = tbody.rows, len = rows.length, i = len; i-- ![]() * * * * { * * * * * tbody.insertBefore(rows[i], rows[prng_int(len)]); * * * * } * * * } * * } * } * <body onload="bodyLoad()" waiting for reply Usenet is not a right. *We[tm] deal with your problem because it looks interesting enough to spend our[tm] time with, not because the solution is urgent for you. *The more demanding you are, the less interesting it becomes for us[tm]. http://catb.org/~esr/faqs/smart-questions.html PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) * -- from <http://www.vortex-webdesign.com/help/hidesource.htm |
#6
| |||
| |||
|
|
On Jul 1, 2:30*pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de wrote: sanju wrote: I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? Quick hack: * /** * ** @return A pseudo-random IEEE-754 double in the interval * ** * <tt>[0, 1)</tt>. * ** @type number * **/ * function prng() * { * * var r = Math.random(); * * // Opera bug workaround * * if (r == 1) r = 0; * * return r; * } * /** * ** Returns a pseudo-random integer value in the interval * ** <tt>[0, top)</tt>, or in the interval <tt>[bottom, top)</tt * ** if <code>bottom</code> was provided. * ** * ** @param top : number * ** @param bottom : optional number * ** @return pseudo-random integer value in the specified interval * ** @type number * **/ * function prng_int(top, bottom) * { * * if (!bottom) bottom = 0; * * return Math.floor(prng() * (top - bottom)) + bottom; * } * /** * ** Sorts the rows of the first table body of the document randomly.. * **/ * function bodyLoad() * { * * // get table object reference * * var t = ... * * if (t) * * { * * * // get table body object reference * * * var tbody = (t.tBodies || [])[0]; * * * if (tbody) * * * { * * * * for (var rows = tbody.rows, len = rows.length, i =len; i-- ![]() * * * * { * * * * * tbody.insertBefore(rows[i], rows[prng_int(len)]); * * * * } * * * } * * } * } * <body onload="bodyLoad()" waiting for reply Usenet is not a right. *We[tm] deal with your problem because it looks interesting enough to spend our[tm] time with, not because the solution is urgent for you. *The more demanding you are, the less interesting it becomes for us[tm]. http://catb.org/~esr/faqs/smart-questions.html PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) * -- from <http://www.vortex-webdesign.com/help/hidesource.htm Thanks Thomas, u r awesome man... God bless you- Hide quoted text - - Show quoted text - |
#7
| |||
| |||
|
|
sanju wrote: I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? Quick hack: * /** * ** @return A pseudo-random IEEE-754 double in the interval * ** * <tt>[0, 1)</tt>. * ** @type number * **/ * function prng() * { * * var r = Math.random(); * * // Opera bug workaround * * if (r == 1) r = 0; * * return r; * } * /** * ** Returns a pseudo-random integer value in the interval * ** <tt>[0, top)</tt>, or in the interval <tt>[bottom, top)</tt * ** if <code>bottom</code> was provided. * ** * ** @param top : number * ** @param bottom : optional number * ** @return pseudo-random integer value in the specified interval * ** @type number * **/ * function prng_int(top, bottom) * { * * if (!bottom) bottom = 0; * * return Math.floor(prng() * (top - bottom)) + bottom; * } * /** * ** Sorts the rows of the first table body of the document randomly. * **/ * function bodyLoad() * { * * // get table object reference * * var t = ... * * if (t) * * { * * * // get table body object reference * * * var tbody = (t.tBodies || [])[0]; * * * if (tbody) * * * { * * * * for (var rows = tbody.rows, len = rows.length, i = len; i-- ![]() * * * * { * * * * * tbody.insertBefore(rows[i], rows[prng_int(len)]); * * * * } * * * } * * } * } * <body onload="bodyLoad()" |
#8
| |||
| |||
|
|
R.sort(randOrd); function randOrd(){ return (Math.round(Math.random())-0.5); } |
#9
| |||
| |||
|
|
var r = Math.random(); // Opera bug workaround if (r == 1) r = 0; |
#10
| |||
| |||
|
|
On Jul 1, 11:30 am, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de wrote: sanju wrote: I have html table and this table contains 10 Rows and 2 column, I want every time this HTML page is called by the user to view the rows Randomly. How can I do this from JavaScript? Hmmm, this code shuffles the rows in just 4 lines : var tbody= (document.getElementById('myTable')).tBodies[0], rows= tbody.rows, i; for (i= rows.length; i; i--) { tbody.appendChild(rows[Math.floor((i)*Math.random())]); } And runs ~10% faster : http://tinyurl.com/56g37t 20.49/100 ms (SAM) |
|
9.97/100 ms (Thomas) |
|
9.09/100 ms (Jorge) |
![]() |
| Thread Tools | |
| Display Modes | |
| |