PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Defaulting the Search Date Range

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Defaulting the Search Date Range

    I'll risk offering amateur code to a bunch of coders. One of my searches is for an historical archive of PDFs going back 12 years. Whilst the old ones are still of value, we like to strongly steer people to the newer ones first (the old ones require broad knowledge of other product changes that may have occurred in the interim).

    So apart from now using sort by date, I've also used some hidden fields in my custom search form to default it to searching the last year of bulletin (if I'd been evil I'd have also set the styles for the date picker to "hidden" but instead I was nice).

    Code:
    <script language="JavaScript1.2" type="text/javascript">
    var today = new Date();
    var dd = today.getDate();
        if(dd<10) dd='0'+dd;
    var mm = today.getMonth()+1;
        if(mm<10) mm='0'+mm;
    var yyyy = today.getFullYear();
    var YYYY = yyyy-1;
    
    
    var thisYear = dd+'/'+mm+'/'+yyyy;
    var lastYear = dd+'/'+mm+'/'+YYYY;
    
    
    document.write('<input type="hidden" name="zoom_datefrom" value="' + lastYear + '" />');
    document.write('<input type="hidden" name="zoom_dateto" value="' + thisYear + '" />');
    </script>
    Mark Gallagher

  • #2
    Thanks for the contribution.

    Certainly using custom javascript to default the search options to something that suit your site specifically is not a bad idea and perhaps will help other people looking to do the same.

    You hinted at this already, but for anyone else looking at this, note that you can default the sort by date option to be descending (latest to oldest). Under "Configure"->"Search Page"->'Provide option to sort results by date'->'Default sort'. So your newer results should show up first by default.
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment

    Working...
    X