Author Topic: Add month string to search  (Read 12787 times)

0 Members and 1 Guest are viewing this topic.

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Add month string to search
« on: August 27, 2007, 07:14:10 AM »
In response to a PM (by the way, don't PM questions to us, use the forum):

Hi Jason,

I'm working with one of the scripts you posted a while back and I'm trying to do a work around for it and I was hoping you could help.

I'm using csvsearch.pl to create a calendar with 12 databases, one for each month. I have the database setup like this db01 for January, db02 for February and so on. Is there a way to extract the month out of the date string to search the month selected? [See below]

Code:

<script>
function CreateDate() {
var datefield = document.getElementById("datefield");
var datefield2 = document.getElementById("datefield2");
function getFieldDate(dateString)
url = url = "http://www.mydomain.com/cgi-bin/csvsearch.pl?mydatabase=db" + month + "&mytemplate=tp1&Date>=" + datefield.value + "&Date<=" + datefield2.value + "&order_by=Date&order=123"
document.location.href = url
}
</script>

What you want to do is add this set of variables to the js:

var d=new Date()

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"

Then where ever you need the month to appear in your url string just add:

+ month[d.getMonth()] +

That will display the month as a word rather than a number from 0-11.

Jason
Founder of www.slipdex.com

Offline EZ

  • Hero Member
  • *****
  • Posts: 1081
    • Babelnotes.be
Re: Add month string to search
« Reply #1 on: August 27, 2007, 12:55:29 PM »
Jason,

I would discourage people from sending you or me PM's.  The forum is there to share knowledge publicly.  Anyway, I added a feature so you can report PM's to me so I can warn people if necessary.

Regards,
EZ