JavaScript - Aasorting Not Sorting Correct Column.. Please Advise
I have a page that takes nodes from drupal and pulls the athletes information and renders it into a roster page via a PHP array. initially the page did not have a logical sort and basically was rendered in the order of the node creation. I added sorttable.js to the file and you could then sort based on the header. However, our head coach wanted it to be sorted onLoad by player number (first column) so I added datatable and set aasorting to 0, asc and it actually sorts the second column (name) instead of column 1. No matter which column I set it to it only sorts the name column. If I could get some advice about how to fix this I would appreciate it.
Code: <style type="text/css">table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after { content: " \25B4\25BE" } </style> <script src="/jscript/sorttable.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#roster').dataTable( { "aaSorting": [[ 0, "asc" ]] } ); } );</script> <table width="100%" cellpadding="2" cellspacing="2" border="1" class="sortable" id="roster" style="border-bottom:1"> <thead> <tr> <?php if( ! empty($vars['sport']->field_sport_show_number) && 1 == $vars['sport']->field_sport_show_number['und'][0]['value'] ): ?> <th class="style4, sortBy" style="width: 14px;" data-sortType="numeric" id="number"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">#</span></th> <?php endif; ?> <th class="style4" style="width: 14px;" ><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Name</span></th> <?php if( ! empty($vars['sport']->field_show_class) && 1 == $vars['sport']->field_show_class['und'][0]['value'] ): ?> <th class="style4" style="width: 14px;"><span style="font-family: Arial, Helvetic Similar TutorialsI have been given files for my site and would like to know what the following script does or could do ? Code: function parseScript(_source) { var source = _source; var scripts = new Array(); // Strip out tags while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) { var s = source.indexOf("<script"); var s_e = source.indexOf(">", s); var e = source.indexOf("</script", s); var e_e = source.indexOf(">", e); // Add to scripts array scripts.push(source.substring(s_e+1, e)); // Strip from source source = source.substring(0, s) + source.substring(e_e+1); } // Loop through every script collected and eval it for(var i=0; i<scripts.length; i++) { try { eval(scripts[i]); } catch(ex) { window.execScript(scripts[i]); } } return source; } this is one of the calls to this script I found in the other site files. Code: document.getElementById(element).innerHTML=parseScript(xmlhttp.responseText); is there a possible security risk on this ? any help on this is grately appreciated. Hi all, The following code is an assigment.I have it running with out any errors.It has to take the array (arrayToshuffle) and through running though the end of the (arrayToshuffle) the string has to be shuffled.We havent learnmt shuffle() yet.) I think the problem is these lines. arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; But no matter what varibles I put in these lines and how much i fiddle I carnt seem to get it to run without repeating the same elements in the output. I dont want anyone to fix it for me just advise on where I could look for problems. Am i missing somthing here? Heres the program if you run it you will see what I mean. <html> <head> <script> var arrayToShuffle = new Array('Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King'); var arraySize = arrayToShuffle.length; document.write('<h1>Array shuffling</h1>'); document.write('<p>Before shuffle: '+arrayToShuffle+'</p>'); SWAPS_TO_MAKE = 30; var index=0; var self_swaps=0; var counter = 0; while(counter < SWAPS_TO_MAKE) { var swapIndex = Math.floor(Math.random()*arraySize+1); arrayToShuffle[index]=arrayToShuffle[swapIndex]; arrayToShuffle[swapIndex]=arrayToShuffle[index]; if(index =swapIndex) { self_swaps++; } counter++; index = (index+1 % arraySize); } document.write('<p>After shuffle: '+arrayToShuffle+'</p>'); document.write('<ul>'); document.write('<li>Swaps made: '+SWAPS_TO_MAKE+'</li>'); document.write('<li>Self swaps: '+self_swaps+'</li>'); document.write('<li>Effective swaps: '+(SWAPS_TO_MAKE-self_swaps)+'</li>'); document.write('<li>Effective rate: '+((SWAPS_TO_MAKE-self_swaps)/SWAPS_TO_MAKE)+'</li>'); document.write('</ul>'); </script> </head> <body> </body> </html> Thanks heaps Shayne Darcy Hi, I am having a slight difficulty and hope someone can easily set me straight. I am trying to use the following code to track a button click and the second onclick event, the urchin tracking is not being completed but the first function is.... can someone please hopefully set me straight easily on the code? Many thanks Steve123. Code: <input type="submit" name="Submit" value="Buy Product" class="buy" onClick="document.form.submit();javascript:urchinTracker('/html/productdeals_button.asp')"> Hello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hi all, I have just stated university a few weeks ago and have never programmed before.I am really stuck on this assigment .In the programm you have to enter you date of birth throught prompt (22).then your year of birth (yyyy),then your month (nov). I am really stuck and have been for days in requards how to put the information gained through prompt function into a date object().So i can get the users day of birth .Heres the code i have written .the varibles num5+num9+num1 is the users input but i just dont know how to assign it to the date object I have tryed heaps of ways but carnt get any thing to work .Please Help. head> <script> var tit1=('<title> Get your Stats </title>'); var tit2=('<h1> IT\'s about time...</h1><br /> ') var num1 =(''); num1=prompt('Enter The Year You Were Born','19XX'); var currentTime = new Date() var year = currentTime.getFullYear() var ansVar = year-num1; //User input year calculation var ageEx = (ansVar/62.7)*100; // Life% calculation var num2=ansVar var num3= ansVar*365.2424; // Days calcuation var month =('janfebmaraprmayjunjulaugsepoctnovdec'); var num5 =(''); num5=prompt('Enter The Month You Where Born','jan'); num5=(num5.substring(0,3)); var lowCas=(num5.toLowerCase());//users input conmverted to lower case/ var num9=prompt ('Enter you date of birth','29'); var d = new Date (num5+num9+num1)//<<<<this random date entered here will give the day. alert (d); //STUCK HERE HOW DO I CONVERT num5+num9+num1 to a day????????:: document.write(tit1); //output document.write(tit2); document.write(('You have lived ')+ageEx.toFixed(0)+('% of your life.<br />')); document.write(('You are ')+ansVar+(' years old.<br />')); document.write (('You are ')+num3.toFixed(0)+(' days old.')); </script> </head> </html> Any advise would be appreciated thanks Shayne darcy. Hi guys, Just a simple question, Since we can't delete object created with document.createElement(), and just let javascript internal garbage collection do the work. I would much appreciate if anybody would advise me, whether we should nullify the object first, for complete deletion by this collector? Thanks for reading, and advising... Hendra. Hi there I've just completed a lovely slideshow script on my homepage. It works great in Firefox, but doesn't display at all in IE. It's on a live test page he http://www.modern-wedding-ideas.co.uk/index2.html I'm sure I'm just missing something really simple. Any help would be greatly appreciated. Also, this is a copy and paste job: I'm a newbie to javascript! So please be gentle. Many thanks Nicola Hi, I would like to sort a table which has inner table using Javascript. When I try to sort, both the outer table and the Inner table are getting sorted. For Eg: I have a table like this: Category1 10.20.30.40 Issue1 sample1 sample2 sample3 Code1 xyz abc The outer table contains Category1,Issue1,Code1 So, after sorting my table should look like this: Category1 10.20.30.40 Code1 xyz abc Issue1 sample1 sample2 sample3 Please provide a solution for this. Good evening all, I have a form at work that was created to allow for clients information to be inputted into this form. However when the row is inserted it is sorted oldest to newest. I would like to change this however i'm not really sure were to start. Below I have added the javascript code that refers to the addrow function. Any advice would be helpful. Code: function addRow(id){ var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0]; var row = document.createElement("TR") var td1 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td1.appendChild(document.createElement("textarea")) var td2 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td2.appendChild(document.createElement("textarea")) var td3 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td3.appendChild(document.createElement("textarea")) var td4 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td4.appendChild(document.createElement("textarea")) var td5 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td5.appendChild(document.createElement("textarea")) var td6 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td6.appendChild(document.createElement("textarea")) row.appendChild(td1); row.appendChild(td2); row.appendChild(td3); row.appendChild(td4); row.appendChild(td5); row.appendChild(td6); tbody.appendChild(row); var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0]; var row = document.createElement("TR") var td1 = document.createElement("TD") td1.appendChild(document.createTextNode("Remarks:")) var td2 = document.createElement("TD") textArea = document.createElement('TEXTAREA') td2.colSpan="4"; td2.appendChild(document.createElement("textarea")) row.appendChild(td1); row.appendChild(td2); tbody.appendChild(row); } Hi everyone, I'm new to the forums. I have been coding some simple javascript but it is really new to me. I coded a segment that you can see below but the part in bold doesn't work. I need it to sort by count descending. I'm having major issues with it. Thanks for the help ahead of time Code: <html> <head> <title>ENGO Lab 2.1</title> <script type="text/javascript"> var d=new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; var month=new Array(12); month[0]="January"; month[1]="February"; month[2]="March"; month[3]="April"; month[4]="May"; month[5]="June"; month[6]="July"; month[7]="August"; month[8]="September"; month[9]="October"; month[10]="November"; month[11]="December"; document.write("Today is " + weekday[d.getDay()] + "<br />" + d.getFullYear() + "/" + month[d.getMonth()] + "/" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds()); </script> <script type="text/javascript"> function sort_descending_count(w){ var sorted = w.sort(); sorted.reverse(); var stuff; var wordCounts = {}; var wordHold = {}; for(i=0; i < w.length; i ++ ){ stuff = sorted[i]; if( wordCounts[stuff] == null ){ wordCounts[stuff] = 1; wordHold[stuff] = stuff; } else{ wordCounts[stuff] += 1; } } var i = 1; wordCounts.sort(); var i = 1; var str = '<table border="1" cellspacing="1" cellpadding="5"><th>Sequence</th><th>Word</th><th>Count</th>'; for( stuff in wordCounts){ str+='<tr><td>'+i+'</td><td>'+stuff+'</td><td>'+wordCounts[stuff]+'</td></tr>'; i = i+1; } str+='</table>'; document.getElementById('change2').innerHTML = txt; } </script> <script type="text/javascript"> function sort_descending(w){ var sorted = w.sort(); sorted.reverse(); var stuff; var wordCounts = {}; for(i=0; i < w.length; i ++ ){ stuff = sorted[i]; if( wordCounts[stuff] == null ){ wordCounts[stuff] = 1; } else{ wordCounts[stuff] += 1; } } var i = 1; var str = '<table border="1" cellspacing="1" cellpadding="5"><th>Sequence</th><th>Word</th><th>Count</th>'; for( stuff in wordCounts){ str+='<tr><td>'+i+'</td><td>'+stuff+'</td><td>'+wordCounts[stuff]+'</td></tr>'; i = i+1; } str+='</table>'; document.getElementById('change2').innerHTML = str; } </script> <script type="text/javascript"> var words; function show_prompt() { var name=prompt("Please input a list of words seperated by a space","Banana Apple Orange"); if (name!=null && name!="") { // split input into array using space var arrayOfWords = name.split(" "); // construct object to save each word and its count var wordCounts = {}; words = arrayOfWords; for(i=0; i < arrayOfWords.length; i ++ ){ var w = arrayOfWords[i]; if( wordCounts[w] == null ){ wordCounts[w] = 1; } else{ wordCounts[w] += 1; } } // output the result var str = '<table border="1" cellspacing="1" cellpadding="5"><th>Word</th><th>Count</th>'; for( w in wordCounts){ str+='<tr><td>'+w+'</td><td>'+wordCounts[w]+'</td></tr>'; } str+='</table>'; document.getElementById('change').innerHTML = str; var button = '<input type="button" onclick="sort_descending(words)" value="Sort with word alphabetically descending">'; var button2 = '<input type="button" onclick="sort_descending_count(words)" value="Sort with word count descending">'; document.getElementById('sorting').innerHTML = button; document.getElementById('sorting2').innerHTML = button2; } else { alert("The Input is Not Valid"); } } window.onload=show_prompt; </script> </head> <body> <br /> <div id="change"> </div> <div id="sorting"> </div> <div id="sorting2"> </div> <div id="change2"> </div> </body> </html>] Not really sure why this isn't working. I've mirrored this webpage from a friend's page - everything is literally identical, save for the references to the databases. His works, and mine doesn't. Here's an example of one of the tables I'm trying to sort: http://www.iblhoops.net/modules.php?...isplay=ratings The code in question for said table: Code: // BEGIN RATINGS TABLE $table_ratings="<table class=\"sortable\"> <thead> <tr bgcolor=$color1><th><font color=$color2>Pos</font></th><th><font color=$color2>Player</font></th><th><font color=$color2>Age</font></th><th><font color=$color2>Sta</font></th><th><font color=$color2>2ga</font></th><th><font color=$color2>2g%</font></th><th><font color=$color2>fta</font></th><th><font color=$color2>ft%</font></th><th><font color=$color2>3ga</font></th><th><font color=$color2>3g%</font></th><th><font color=$color2>orb</font></th><th><font color=$color2>drb</font></th><th><font color=$color2>ast</font></th><th><font color=$color2>stl</font></th><th><font color=$color2>tvr</font></th><th><font color=$color2>blk</font></th><th><font color=$color2>o-o</font></th><th><font color=$color2>d-o</font></th><th><font color=$color2>p-o</font></th><th><font color=$color2>t-o</font></th><th><font color=$color2>o-d</font></th><th><font color=$color2>d-d</font></th><th><font color=$color2>p-d</font></th><th><font color=$color2>t-d</font></th><th><font color=$color2>Foul</font></th><th><font color=$color2>Inj</font></th></tr> </thead> <tbody> "; $i=0; while ($i < $num) { if ($yr == "") { $name=mysql_result($result,$i,"name"); $team=mysql_result($result,$i,"teamname"); $pid=mysql_result($result,$i,"pid"); $pos=mysql_result($result,$i,"altpos"); $p_ord=mysql_result($result,$i,"ordinal"); $age=mysql_result($result,$i,"age"); $inj=mysql_result($result,$i,"injured"); $r_2ga=mysql_result($result,$i,"r_fga"); $r_2gp=mysql_result($result,$i,"r_fgp"); $r_fta=mysql_result($result,$i,"r_fta"); $r_ftp=mysql_result($result,$i,"r_ftp"); $r_3ga=mysql_result($result,$i,"r_tga"); $r_3gp=mysql_result($result,$i,"r_tgp"); $r_orb=mysql_result($result,$i,"r_orb"); $r_drb=mysql_result($result,$i,"r_drb"); $r_ast=mysql_result($result,$i,"r_ast"); $r_stl=mysql_result($result,$i,"r_stl"); $r_blk=mysql_result($result,$i,"r_blk"); $r_tvr=mysql_result($result,$i,"r_to"); $r_sta=mysql_result($result,$i,"sta"); $r_foul=mysql_result($result,$i,"r_foul"); $r_totoff=mysql_result($result,$i,"oo")+mysql_result($result,$i,"do")+mysql_result($result,$i,"po")+mysql_result($result,$i,"to"); $r_totdef=mysql_result($result,$i,"od")+mysql_result($result,$i,"dd")+mysql_result($result,$i,"pd")+mysql_result($result,$i,"td"); $r_oo=mysql_result($result,$i,"oo"); $r_do=mysql_result($result,$i,"do"); $r_po=mysql_result($result,$i,"po"); $r_to=mysql_result($result,$i,"to"); $r_od=mysql_result($result,$i,"od"); $r_dd=mysql_result($result,$i,"dd"); $r_pd=mysql_result($result,$i,"pd"); $r_td=mysql_result($result,$i,"td"); $r_bird=mysql_result($result,$i,"bird"); $draftyear=mysql_result($result,$i,"draftyear"); $exp=mysql_result($result,$i,"exp"); $cy=mysql_result($result,$i,"cy"); $cyt=mysql_result($result,$i,"cyt"); $yearoffreeagency=$draftyear+$exp+$cyt-$cy; } else { $name=mysql_result($result,$i,"name"); $team=mysql_result($result,$i,"team"); $pid=mysql_result($result,$i,"pid"); $r_2ga=mysql_result($result,$i,"r_2ga"); $r_2gp=mysql_result($result,$i,"r_2gp"); $r_fta=mysql_result($result,$i,"r_fta"); $r_ftp=mysql_result($result,$i,"r_ftp"); $r_3ga=mysql_result($result,$i,"r_3ga"); $r_3gp=mysql_result($result,$i,"r_3gp"); $r_orb=mysql_result($result,$i,"r_orb"); $r_drb=mysql_result($result,$i,"r_drb"); $r_ast=mysql_result($result,$i,"r_ast"); $r_stl=mysql_result($result,$i,"r_stl"); $r_blk=mysql_result($result,$i,"r_blk"); $r_tvr=mysql_result($result,$i,"r_tvr"); $r_totoff=mysql_result($result,$i,"r_oo")+mysql_result($result,$i,"r_do")+mysql_result($result,$i,"r_po")+mysql_result($result,$i,"r_to"); $r_totdef=mysql_result($result,$i,"r_od")+mysql_result($result,$i,"r_dd")+mysql_result($result,$i,"r_pd")+mysql_result($result,$i,"r_td"); $r_oo=mysql_result($result,$i,"r_oo"); $r_do=mysql_result($result,$i,"r_do"); $r_po=mysql_result($result,$i,"r_po"); $r_to=mysql_result($result,$i,"r_to"); $r_od=mysql_result($result,$i,"r_od"); $r_dd=mysql_result($result,$i,"r_dd"); $r_pd=mysql_result($result,$i,"r_pd"); $r_td=mysql_result($result,$i,"r_td"); } if(($i % 2)==0) { $bgcolor="FFFFFF"; }else{ $bgcolor="EEEEEE"; } if ($tid == 0) { $table_ratings=$table_ratings." <tr bgcolor=$bgcolor><td>$pos</td><td><a href=\"http://www.iblhoops.net/modules.php?name=Player&pa=showpage&pid=$pid\">$name</a></td><td>$age</td><td>$r_sta</td><td>$r_2ga</td><td>$r_2gp</td><td>$r_fta</td><td>$r_ftp</td><td>$r_3ga</td><td>$r_3gp</td><td>$r_orb</td><td>$r_drb</td><td>$r_ast</td><td>$r_stl</td><td>$r_tvr</td><td>$r_blk</td><td>$r_oo</td><td>$r_do</td><td>$r_po</td><td>$r_to</td><td>$r_od</td><td>$r_dd</td><td>$r_pd</td><td>$r_td</td><td>$r_foul</td><td>$inj</td></tr> "; } else { if ($p_ord > 959) { $table_ratings=$table_ratings." <tr bgcolor=$bgcolor><td>$pos</td><td>(<a href=\"http://www.iblhoops.net/modules.php?name=Player&pa=showpage&pid=$pid\">$name)*</a></td><td>$age</td><td>$r_sta</td><td>$r_2ga</td><td>$r_2gp</td><td>$r_fta</td><td>$r_ftp</td><td>$r_3ga</td><td>$r_3gp</td><td>$r_orb</td><td>$r_drb</td><td>$r_ast</td><td>$r_stl</td><td>$r_tvr</td><td>$r_blk</td><td>$r_oo</td><td>$r_do</td><td>$r_po</td><td>$r_to</td><td>$r_od</td><td>$r_dd</td><td>$r_pd</td><td>$r_td</td><td>$r_foul</td><td>$inj</td></tr> "; } elseif ($r_bird == 0) { $table_ratings=$table_ratings." <tr bgcolor=$bgcolor><td>$pos</td><td><i><a href=\"http://www.iblhoops.net/modules.php?name=Player&pa=showpage&pid=$pid\">$name</i></a></td><td>$age</td><td>$r_sta</td><td>$r_2ga</td><td>$r_2gp</td><td>$r_fta</td><td>$r_ftp</td><td>$r_3ga</td><td>$r_3gp</td><td>$r_orb</td><td>$r_drb</td><td>$r_ast</td><td>$r_stl</td><td>$r_tvr</td><td>$r_blk</td><td>$r_oo</td><td>$r_do</td><td>$r_po</td><td>$r_to</td><td>$r_od</td><td>$r_dd</td><td>$r_pd</td><td>$r_td</td><td>$r_foul</td><td>$inj</td></tr> "; } else if ($fayr == "" OR $yearoffreeagency == $fayr) { $table_ratings=$table_ratings." <tr bgcolor=$bgcolor><td>$pos</td><td><a href=\"http://www.iblhoops.net/modules.php?name=Player&pa=showpage&pid=$pid\">$name</a></td><td>$age</td><td>$r_sta</td><td>$r_2ga</td><td>$r_2gp</td><td>$r_fta</td><td>$r_ftp</td><td>$r_3ga</td><td>$r_3gp</td><td>$r_orb</td><td>$r_drb</td><td>$r_ast</td><td>$r_stl</td><td>$r_tvr</td><td>$r_blk</td><td>$r_oo</td><td>$r_do</td><td>$r_po</td><td>$r_to</td><td>$r_od</td><td>$r_dd</td><td>$r_pd</td><td>$r_td</td><td>$r_foul</td><td>$inj</td></tr> "; } } $i++; } $table_ratings=$table_ratings." </tbody> </table> "; if ($tid != 0) { $table_totals=$table_totals." <table class=\"sortable\"> <thead> <tr bgcolor=$color1><th><font color=$color2>Pos</font></th><td colspan=3><font color=$color2>Player</font></th><th><font color=$color2>g</font></th><th><font color=$color2>gs</font></th><th><font color=$color2>min</font></th><th><font color=$color2>fgm</font></th><th><font color=$color2>fga</font></th><th><font color=$color2>ftm</font></th><th><font color=$color2>fta</font></th><th><font color=$color2>3gm</font></th><th><font color=$color2>3ga</font></th><th><font color=$color2>orb</font></th><th><font color=$color2>reb</font></th><th><font color=$color2>ast</font></th><th><font color=$color2>stl</font></th><th><font color=$color2>to</font></th><th><font color=$color2>blk</font></th><th><font color=$color2>pf</font></th><th><font color=$color2>pts</font></th></tr> </thead> <tbody> "; Any ideas? Got this script from the Sam's Teach Yourself Javascript In 24 Hours book, and I'm a little confused with regards to this script I came across, or more specifically, the part of the script I've outlined in red. Code: <script language="javascript" type="text/javascript"> function numcompare(a,b) { return a-b; } nums = new Array (17, 902, 30, 10, 200, 4, 506); sortednums = nums.sort(numcompare); output = sortednums.join(", "); document.write(output); </script> I really don't understand how the numcompare() function works, and the book doesn't explain it very well. Any help with deciphering this piece of code? Thanks in advance. Hashim. not sure why this wont sort in asending order... i tend to make little dumb mistakes sorry. :/ Code: <script type="text/javascript"> function sort(nums) { var rangeStart = 0; var rangeEnd = nums.length - 1; var i = 0; var minPosition = rangeStart; while(rangeStart < rangeEnd) { // find minumum for(i = rangeStart; i < rangeEnd; i++) { if(nums[i] <= nums[minPosition+1]) { minPosition = i; } } // swap var temp = nums[rangeStart]; nums[rangeStart] = nums[minPosition]; nums[minPosition] = temp; // change range rangeStart++; } } document.write("<h3>Examples</h3>"); first10 = [2,3,5,7,9,4,8,0,6,1]; document.write("<div>Sorting <tt>["+first10+"]</tt> with current code gives "); sort(first10); document.write("<tt>["+first10+"]</tt></div>"); ages = [19,34,20,66,82,53,88,74,39,13]; document.write("<div>Sorting <tt>["+ages+"]</tt> with current code gives "); sort(ages); document.write("<tt>["+ages+"]</tt></div>"); </script> Say I have a gallery of 16 images and I have a menu for the gallery to sort the images by Most Viewed, Most Recent, Highest Rating, A-Z, Z-A.. if I were to click 1 of the menu links it will change the order of the images but is it possible to actually show the images MOVING into their new places? Looking for a jquery solution if possible.. if not still open to anythin that would work What I need help with is sorting the [0] of my array. I need it to sort so that if the user puts in his last name, whether its uppercase or lowercase (Adams, adams), it will sort through the list of students I add, and put them in an alphabetic order i.e adams, Adams, cook, Douglas....and so on. Here is the code that I have below for just sorting by last name, which will seperate the lowercase entries from the uppercase entries. That would be the opposite of what I want. I had it sorted so that it would sort the [o], which is where the last name value is located. Any thoughtful help would be appreciated. Code: function Last_names( s1, s2 ) { if ( s1[0] > s2[0] ) return 1; return 0; } function sortLast(form) { StudentsLists.sort( Last_names ); windows(form);//calling the windows function each time the sortLast function is called } So, I'm using code like the following and getting errors: result = a list of cars with each property separated by ',' and each car separated by '|' This code creates and populates the array (seems to work) Code: var carList = new Array(); var cars = new Array(); var properties = new Array(); cars = result.split("|"); for(var i=0; i<cars.length;i++){ properties = cars[i].split(","); carlist[carlist.length++] = new car(items[0],items[1],items[2]); function car(id,make,model){ carID = id; carMake = make; carModel = model; } Later, I want to sort the array and call it like this: carList.sort(carSort); here's the sort code Code: function carSort(a, b){ var x = a.carMake.toLowerCase(); var y = b.carMake.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); } I get the error that "a.carMake does not exist" (in firebug). What am I doing wrong? Hello, I have an Object, containing an object, containing an object....etc. So, it's an Object of objects. Not an Array of objects. And now I want to sort this Object of objects. Is there a "native" way in JavaScript to sort an object? Or do I understand it correctly, that I first have to convert the Object to an Array, and than perform an array.sort ? This question is just for my understanding of JavaScript, so I don't go into the wrong direction. Tnx in advance for any explanation. I am trying to make an addition to a .js plugin for a wiki. Currently it does not support sorting my IP address. So far I have created the below code which does more than the script initially did, but is still not sorting 100% correctly. Any tips? Code: sort_ipaddr: function(a,b){ aa = a[0].split(".",4); bb = b[0].split(".",4); var counti = 0; for (var i=0; i<4; i++) { if (parseInt(parseFloat(aa[i])) == parseInt(parseFloat(bb[i]))){} if (parseInt(parseFloat(aa[i])) < parseInt(parseFloat(bb[i]))){counti--} if (parseInt(parseFloat(aa[i])) > parseInt(parseFloat(bb[i]))){counti++} } return counti; }, EDIT I've also tried this which is closer but still not there. Code: sort_ipaddr: function(a,b){ aa = a[0].split(".",4); bb = b[0].split(".",4); var resulta = (aa[3]+(aa[2]*256)+(aa[1]*256*256)+(aa[0]*256*256*256)); var resultb = (bb[3]+(bb[2]*256)+(bb[1]*256*256)+(bb[0]*256*256*256)); return resulta-resultb; }, This results in a list like so: 10.1.15.22 10.1.16.22 10.1.15.23 10.1.15.24 10.1.16.24 10.1.15.25 in IE9 Browser list of country names sorting on keys. we are using Ajax javascript: Code: var data= remoteRequest(url); the data like Code: data={" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"} name_set= eval('('+data+')'); it fine in all browser the array like Code: name_set[11]=Australia name_set[14]=Bermuda name_set[CAN]=Canada name_set[12]=France name_set[15]=Germany name_set[IND]=India name_set[16]=Russia name_set[13]=South Africa name_set[10]=UK name_set[USA]=United States but in the IE9 browser array keys sorting as like. Code: name_set[10]=UK name_set[11]=Australia name_set[12]=France name_set[13]=South Africa name_set[14]=Bermuda name_set[15]=Germany name_set[16]=Russia name_set[CAN]=Canada name_set[IND]=India name_set[USA]=United States so please help me, how to stop the array sorting in IE9. thanks in Advance, Venu |