/    Sign up×
Community /Pin to ProfileBookmark

hi.. need help with code..

hi wanted to ask whether you guys know anythin wrong with this code..
this code should be able to select and de-select (change a class) of a <TD> corresponding to the checked checkboxes.. if selected the class is daySelected and if its de-selected, the class is dayNotAllocated..
The table contains 21 cells which corresponds to the date until 3 weeks ahead from the date specified in a hidden input which is [B]document.calendar.fromDate.value[/B] in a form of dd/mm/yyyy..

[CODE] function rateGlobalSelect() {
var startDateString = [B]document.calendar.fromDate.value;[/B]
var beginDatePre = Date.parse(startDateString);
var beginDate = new Date(beginDatePre);

//var beginDay = beginDate.getDay();

var monCheck = document.getElementById(‘mon’).checked;
var tueCheck = document.getElementById(‘tue’).checked;
var wedCheck = document.getElementById(‘wed’).checked;
var thuCheck = document.getElementById(‘thu’).checked;
var friCheck = document.getElementById(‘fri’).checked;
var satCheck = document.getElementById(‘sat’).checked;
var sunCheck = document.getElementById(‘sun’).checked;

var dayArray = new Array();
dayArray[0] = monCheck;
dayArray[1] = tueCheck;
dayArray[2] = wedCheck;
dayArray[3] = thuCheck;
dayArray[4] = friCheck;
dayArray[5] = satCheck;
dayArray[6] = sunCheck;

var refRe = /ra(S+)_(S+)/;
var countElement = document.calendar.elements.length;

for (i=0; i < countElement; i++) {
var dayRef = document.calendar.elements[i];
var curEl = dayRef.name;
var matches = refRe.exec(curEl);

if (matches) {
var rateTypeId = parseInt(matches[1]);
var daysFromPeriodStart = parseInt(matches[2]);

// find current date here using startdate + daysFromPeriodStart
var curDay = new Date((daysFromPeriodStart * 1000 * 60 * 60 * 24) + beginDate.getTime());

var selectedDay = curDay.getDay();

if (dayArray[selectedDay]) {
//set class to selected
dayRef.className = ‘daySelected’;
//var selectedDay = beginDay + daysFromPeriodStart;
}
}
}
}[/CODE]

thank you for the time.. ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMay 09.2006 — ... in a form of dd/mm/yyyy.[/QUOTE]
That format is going to be a problem. The [B]Date.parse()[/B] method will only accept such a delimited date string in [B]mm/dd/yyyy[/B] format. Once you address that, you can combine the following two lines:

var beginDatePre = Date.parse(startDateString);

var beginDate = new Date(beginDatePre);

into this single line -- with equivalent results (unless you need the milliseconds representation for some other use):

var beginDate = new Date(startDateString);
×

Success!

Help @stanleyns spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...