tags:

views:

37

answers:

1

Hello everyone,

Let me start by saying that I'm not a power-JavaScript/jQuery programmer, I do very basic things with it, yet sometimes things get a little hairy for me, like this one.

My case:

I have a list of testimonials (around 20) and every week (Mondays) I need to updated them.

My problem:

I update them manually. I mean, I open Dreamweaver, update the jQuery code for the corresponding testimonial number, and upload to server.

What I need:

A way to have this be automated... as best as possible.

HTML of testimonials:

<body>
<div class="quotes-container quote-1">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
<div class="quotes-container quote-2">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
<div class="quotes-container quote-3">
  <div class="quote">Testimonial...</div>
  <div class="author">Author</div>
</div>
...
</body>

My jQuery used to change the testimonial:

$(function(){ $('#quotes-wrapper').load('/static-files/testimonials.html div.quote-1'); });

As you can see all I need to do is to manually change div.quote-1 to div.quote-2 or div.quote-3 and so on.

But I know there's got to be a way to have jQuery change these testimonials 'dynamically' every Monday (or Tuesday, or any day I choose for that matter), and not have to keep reminders around to not forget to change the testimonials every Monday.

Any ideas how can this be accomplished?

Thanks in advance.

+1  A: 

You could find out the week of year to select the div:

(got the code from http://javascript.about.com/library/blweekyear.htm)

Date.prototype.getWeek = function() {
  var onejan = new Date(this.getFullYear(),0,1);
  return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}
$(function(){
  var today = new Date();
  var weekno = today.getWeek();
  $('#quotes-wrapper').load('/static-files/testimonials.html div.quote-'+weekno);
});
elektronikLexikon
elektronikLexikon, I tried it but it didn't work, it hides the entire "#quotes-wrapper" container.I added a ' to the end of "+weekno" and it now shows the "#quotes-wrapper" container though, but no testimonial:".load('/static-files/testimonials.html div.quote-'+weekno');"
Ricardo Zea
weekno is 38 in this week. Is there a "div.quote-38"?
elektronikLexikon
Oh wow! It worked! :DThis is pretty much what I needed, all I need to do now is just change my div.quote-1, div.quote-2, div.quote-3, etc, to the proper number of the week we are at right now.I only have a total of 21 testimonials, so I was numbering them 1 through 21 of course. Now all I need to do is change the numbers to the corresponding week.Thanks a lot elektronikLexikon!
Ricardo Zea