SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript onload cross-browser issues

    I am using the table sorting script by Frequency Decoder on a particular table in my application. What I want to do is set a cookie to store the details about the column that was sorted so that when a visitor comes back to the same page, the column would be sorted as per the user's previous sort order.

    Setting and retrieving values from a cookie is not a problem. Telling the script to sort a column on the onload event of the page is. The code I wrote works in Firefox but not in IE.

    I have attached sample code for you to have a look. I would appreciate it if someone could help me out.

    HTML Code:
    <html>
    	<head>
    		<title>Table Sort Test</title>
    		<script type="text/javascript" src="tablesort.js"></script>
    		<style>
    			.highlight { background-color: #FFD; }
    		</style>
    	</head>
     <body>
      
    	<table id="MySortTable" class="sortable colstyle-highlight">
    		<tr>
    			<th class="sortable-numeric">ID</th>
    			<th class="sortable-text">Name</th>
    			<th class="sortable-numeric">Rating</th>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>Sunflower</td>
    			<td>21</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>Rose</td>
    			<td>15</td>
    		</tr>
    		<tr>
    			<td>3</td>
    			<td>Tulip</td>
    			<td>18</td>
    		</tr>
    		<tr>
    			<td>4</td>
    			<td>Lilly</td>
    			<td>25</td>
    		</tr>
    		<tr>
    			<td>5</td>
    			<td>Orchid</td>
    			<td>27</td>
    		</tr>
    		<tr>
    			<td>6</td>
    			<td>Marigold</td>
    			<td>30</td>
    		</tr>
    	</table>
    
    	<script type="text/javascript">
    		function addLoadEvent(func) {
    			var oldonload = window.onload;
    			if (typeof window.onload != 'function') {
    				window.onload = func;
    			} else {
    				window.onload = function() {
    					oldonload();
    					func();
    				}
    			}
    		}
    
    		addLoadEvent(SortTable);
    
    		function SortTable()
    		{
    			alert('sorting');
    			fdTableSort.jsWrapper('MySortTable', [1]);
    		}
    
    		function sortCompleteCallbackMySortTable()
    		{
    			var position = fdTableSort.pos;
    			alert(position);
    		}
    	</script>
    
     </body>
    </html>
    Attached Files Attached Files

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That should not be in the BODY. That's the whole point of it being unobtrusive. Put it in the HEAD, preferably in the same file as tablesort.js.

  3. #3
    SitePoint Guru Husain's Avatar
    Join Date
    Sep 2001
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did put it in the head section first and then moved it inside BODY to check if that worked. Both places didn't work


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •