If you just need wednesday, you should be able to do something like this:
function next(today) {
var offset = (today.getDay() < 3) ? 0 : 7;
var daysUntilWednesday = 3 + offset - today.getDay();
return new Date().setDate(today.getDate() + daysUntilWednesday);
}
var wed = next( new Date() );
EDIT:
or something like this? http://jsfiddle.net/zy7F8/1/
var days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
function next(day) {
var today = new Date();
var today_day = today.getDay();
day = day.toLowerCase();
for (var i = 7; i--;) {
if (day === days[i]) {
day = (i <= today_day) ? (i + 7) : i;
break;
}
}
var daysUntilNext = day - today_day;
return new Date().setDate(today.getDate() + daysUntilNext);
}
// insert a week day
alert(new Date(next( "Wednesday" )));
EDIT: Made a correction for days entered that are yet to come in the same week.