Solved

initializing jquery makes page load very slow

Posted on 2010-09-23
3
780 Views
Last Modified: 2012-05-10
I have an html document which has a 1 column table holding  jquery datepicker(see attached code).

When I simply attach the datepicker using:

               //code lines 31 onwards
            $('.date-pick').each(function(){
                $(this).datepicker();
            });

the table loads quikcky, but when I extend the datepicker functionality as follows:

            $('.date-pick').each(function(){
                $(this).datepicker();
                  $(this).datepicker('option', {dateFormat: 'dd/mm/yy'});
                  $(this).datepicker('option', {autoSize: true });
                  $(this).datepicker('option', {showButtonPanel: true });
                  $(this).datepicker('option', {onClose: function(dateText, inst) {
                              //close handler
                              //checkAndUpdateDate(dateText, inst);
                        }
                  });
                  $(this).datepicker('option', {onBlur: function(dateText, inst) {
                              //blur handler
                              //checkAndUpdateDate(dateText, inst);
                        }
                  });
            });
the page takes a long time to load and if too many rows are used, thepage script freezes.

How can I customize the behaviour of the datepicker without causing a delay?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link type="text/css" href="css/sunny/jquery-ui-1.8.4.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="assets/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="assets/jquery-ui-1.8.4.custom.min.js"></script>


<script type="text/javascript">
	$(document).ready(function(){
		var tbody = document.getElementById('tbod');
							   
		for (var i = 0; i < 150; i++){
			var tr = document.createElement('tr');
			tbody.appendChild(tr);
			
			var tdDate = document.createElement('td');
			var tdInput = document.createElement('input');
			tdInput.setAttribute("id", 'dpicker' + i);
			tdInput.className = 'date-pick';

			tdDate.appendChild(tdInput);
			tr.appendChild(tdDate);
			
		}
		$('.date-pick').each(function(){
		    $(this).datepicker();
			$(this).datepicker('option', {dateFormat: 'dd/mm/yy'});
			$(this).datepicker('option', {buttonText: 'Velg dato'});
			$(this).datepicker('option', {autoSize: true });
			$(this).datepicker('option', {showButtonPanel: true });
			$(this).datepicker($.datepicker.regional['no']);
			$(this).datepicker('option', {onClose: function(dateText, inst) {
					checkAndUpdateDate(dateText, inst);
				}
			});
			$(this).datepicker('option', {onBlur: function(dateText, inst) {
					checkAndUpdateDate(dateText, inst);
				}
			});

		});

//		$('.date-pick').datePicker({clickInput:true})
					   
	});
</script>

</head>

<body>

	<table class="tab" width="100" border="1">
  	 	<thead>
    		<tr>
        		<th id="head-date" class="date" scope="col">Date</th>
      		</tr>
    	</thead>

		<col width="100px" />
    
	    <tbody id="tbod">
    	</tbody>
	</table>


</body>
</html>

Open in new window

0
Comment
Question by:Viking46
3 Comments
 
LVL 15

Expert Comment

by:crisco96
Comment Utility
What browser are you using? IE 6 is particularly slow when doing anything with javascript, try loading the "slow" page in the latest version of firefox or chrome and see if it's any faster.
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:Viking46
Comment Utility
Thank you Crisco 96, I am using FF and it wasn't a browser issue.

Thank you HainKurt, setDefaults is what I was looking for.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn how to count occurrences of each item in an array.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now