Click to See Complete Forum and Search --> : Hi need help for changing class of a td by ticking a check box


stanleyns
05-03-2006, 11:05 PM
hi guys.. i need help in a project..

okay first let me explain what i got..

i got 7 check box for each day of the week.. (eg. mon until sunday)
then i got a calendar type table where i got 9 TD in each row.. where as the first two TD are only labels and the last seven are the days of the week..
then in the next row, i got datas that i retrieve from the database..

what i need to do is when i click a certain day in the checkbox, i would like to change the class of all the TD that has the responding day as the one that i have checked in the check box.. (remember how my table got 7 td in a row that correspond with the days of the week..)

please help and thank you very much... :D

kingroon
05-03-2006, 11:49 PM
What language are you writing your data to the page from your db in? ASP? PHP?

sridhar_423
05-04-2006, 12:25 AM
<style>
.xcls { background-color:#FFFFCC; font-family:Arial,Arial,Helvetica,sans-serif; font-size:10px; font-weight: bold; }
.fst { background-color:#FFFFFF; font-family:Arial,Arial,Helvetica,sans-serif; font-size:10px; font-weight: bold; }
</style>

<script>
function function1(val,flag){
val=Number(val);
m=tbl1.getElementsByTagName("td");
n=tbl1.getElementsByTagName("tr");

for(i=0;i<n.length;i++){
if(flag)
m[i*7+val-1].className="xcls";
else
m[i*7+val-1].className="fst";
}
}
</script>
<BODY>

<input type=checkbox name=chkk value=1 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=2 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=3 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=4 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=5 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=6 onClick="function1(this.value,this.checked)"><br>
<input type=checkbox name=chkk value=7 onClick="function1(this.value,this.checked)"><br>
<table id="tbl1" border=1>
<tr><td class="fst">1</td><td class="fst">2</td><td class="fst">3</td><td class="fst">4</td><td class="fst">5</td><td class="fst">6</td><td class="fst">7</td></tr>
<tr><td class="fst">1</td><td class="fst">2</td><td class="fst">3</td><td class="fst">4</td><td class="fst">5</td><td class="fst">6</td><td class="fst">7</td></tr>
<tr><td class="fst">1</td><td class="fst">2</td><td class="fst">3</td><td class="fst">4</td><td class="fst">5</td><td class="fst">6</td><td class="fst">7</td></tr>
<tr><td class="fst">1</td><td class="fst">2</td><td class="fst">3</td><td class="fst">4</td><td class="fst">5</td><td class="fst">6</td><td class="fst">7</td></tr>
<tr><td class="fst">1</td><td class="fst">2</td><td class="fst">3</td><td class="fst">4</td><td class="fst">5</td><td class="fst">6</td><td class="fst">7</td></tr>
</table>

</BODY>

stanleyns
05-04-2006, 12:37 AM
thx for the help sridhar.. but since im kinda new in javascript, the val that you put as the parameter, is that suppose to be in a integer?
i think i can get that from using the getDay function right?

edit: and also.. if i got the value for example 01/06/2006, how do i get the day of that date (i want to take the number of the day.. example, 0 = sunday, 1=monday, etc.) ?? using javascript..


btw, im using php..

sridhar_423
05-04-2006, 01:18 AM
dt=new Date("02-12-2006"); //mm-dd-yyyy format
day_val=dt.getDay();

also, in the code i've kept only 7 td's. replace "7" with "9" as you have 9 td's