views:

34

answers:

3

I am using the Quicksand jquery scripts on an HTML page and using simple select controls:

<select name="sort" style="vertical-align:middle;" id="cboSort">
    <option value="1" selected="selected">Low to High</option>
    <option value="2">High to Low</option>
</select>

I want to be able to have the quicksand scripts run on page load but I have no idea how to do that, I am learning javascript so I am a bit confused. Basically I want the items to be already sorted from Low to High on page load. This is a simple one page website.

please help

A: 

You can wrap the code you want to run in jQuery's $(document).ready() construct:

$(document).ready(function() {
    // Your code goes here...
});

This will only run once the whole page is loaded.

Gus
both answers are good, but because the sort is in a jquery script file I am going to try this one when I get home. Now quick qeustion. If I do this,will I still be able to use the select controls to run the quicksand scripts after the page has loaded?
mattgcon
I wasn't too familiar with quicksand, but after a quick look at the demo code here: http://razorjack.net/quicksand/demos/one-set-clone.html it appears that the sort functionality is bound to your select element's onchange event. In that case, you could simply fire the element's `change()` function after running the quicksand scripts to perform the first sort. e.g.: `$('#cboSort').change() ;`
Gus
Gus, I placed the sort code in a js file so it is outside the page and contained within the main script function. I tried the $(document).ready(function() but it didnt run on load, did I forget to do something else. Does a reference need to be placed within the body tag
mattgcon
Wait it did run the script however for some reason it did not sort like it was supposed to
mattgcon
Gus it is failing on this line // attempt to call Quicksand on every form change $('select').change(
mattgcon
Gus ok figure that issue out, however, the sorting and filtering will not work now after the page is load, I need to be able to apply filtering and sorting after the page is load as well. Can you help me
mattgcon
A: 
<html>
<head>
<script type="text/javascript">
function sortFunction() {
//logic
}
</script>
</head>
<body onload="sortFunction()">
<select name="sort" style="vertical-align:middle;" id="cboSort">
    <option value="1" selected="selected">Low to High</option>
    <option value="2">High to Low</option>
</select>
</body>
</html>

try that, the other answer works too

Ascherer
A: 

this was fixed using autoselect and variable switch

mattgcon