PDA

View Full Version : 'if, else if' question DIFFERENT TOPIC



h8ids
Jul 25th, 2006, 05:46 PM
I'd like to change the background color of a table cell based upon a checkbox state. The following HTML refers to the second checkbox. Having trouble getting both "document.form2.blah.blah" lines working.
Not certain where I'm going wrong with the following code.
Is it feasible to have multiple events if one condition is true?

HTML:

<TD bgcolor="#CCCCCC" name='AcceptDenyRegNO'><center>Denied<br><input id="AcceptDenyRegNO" disabled type='checkbox' name='AcceptDenyRegNO' <?php if ($myrow2["AcceptDeny"] == 'NO') echo "checked"?>></center></TD>

JavaScript:

function EditON(){
if (something)
document.form2.something.something;

else if (document.form2.AcceptDenyRegNO.checked)
document.form2.EditRecord.disabled=false;
document.form2.AcceptDenyRegNO.bgcolor="#FF0000";
}

Mr J
Jul 25th, 2006, 08:25 PM
Try changing this line

document.form2.AcceptDenyRegNO.bgcolor="#FF0000";

to

document.form2.AcceptDenyRegNO.style.backgroundColor="#FF0000";

h8ids
Jul 25th, 2006, 09:43 PM
Adjusted line of code to your suggestion.
No errors. Yet the background color remains the same.

I am calling the javascript.js file from the BODY tag (<body onload="EditON()">)



Try changing this line

document.form2.AcceptDenyRegNO.bgcolor="#FF0000";

to

document.form2.AcceptDenyRegNO.style.backgroundColor="#FF0000";

_Aerospace_Eng_
Jul 25th, 2006, 09:45 PM
Without brackets in the else if statements only the next line after the if else will be executed. You need brackets if you want more than one line to be executed

function EditON(){
if (something)
{
document.form2.something.something;
}

else if (document.form2.AcceptDenyRegNO.checked){
document.form2.EditRecord.disabled=false;
document.form2.AcceptDenyRegNO.style.backgroundColor="#FF0000";
}
}

h8ids
Jul 25th, 2006, 10:06 PM
Corrected the bracket problem too. No errors, nor are the background colors updating.

HTML:


<TD bgcolor="#CCCCCC" name='AcceptDenyRegNO'><center>Denied<br><input id="AcceptDenyRegNO" disabled type='checkbox' name='AcceptDenyRegNO' checked></center></TD>


Javascript include file:

function EditON(){
if (document.form2.AcceptDenyChrNO.checked){
document.form2.EditRecord.disabled=false,
document.form2.AcceptDenyChrNO.style.backgroundColor="#FF0000";
} else if (document.form2.AcceptDenyRegNO.checked){
document.form2.EditRecord.disabled=false,
document.form2.AcceptDenyRegNO.style.backgroundColor="#FF0000";
} else if (document.form2.AcceptDenyCCNO.checked){
document.form2.EditRecord.disabled=false,
document.form2.AcceptDenyCCNO.style.backgroundColor="#FF0000";
}
}

_Aerospace_Eng_
Jul 25th, 2006, 10:23 PM
Post the rest of your html please or post a link.

h8ids
Jul 26th, 2006, 03:32 PM
IE v6 shows a red border around all "Denied" checkboxes that have been dynamically checked. It's picking up on the background area of the checkbox. But the cell isn't changing color.
Firefox v1.5 shows nothing.

SOURCE CODE:

<HTML>
<title>Professors' Submitted Courses</title>
<head>
<script src="javascript.js"></script>
</head>
<body onload="EditON()" alink="#0000FF" link="#0000FF" vlink="#C0C0C0" topmargin="0">

<!-- Form Border image and -->
<div style="position: absolute; left: 5%;">
<div style="position: absolute; left: 35px; top: 0px; width:243px; z-index:0" id="Page_Title"><img border="0" src="titlebar800_600.jpg">
</div>

<!-- Beginning of form input -->
<form name="form2">

<!-- Table positioning -->
<div style="position: absolute; width: 635px; left: 40px; top: 85px; z-index:1" id="Top_HR">

<!-- Collection of record data -->
<-- Table formatting and sorting buttons -->
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<TABLE BORDER=0 width='631' cellpadding=4 cellspacing=0 bgcolor='#FFFFFF'>
<thead bgcolor='lightyellow'>
<TR>
<TH>Course title</TH>
<TH colspan='3'>Review status</TH>
<TH>Comments</TH>
</TR></thead>

<!-- CHAIR RESULTS -->
<tbody id=\"offTblBdy\">
<TR>
<TD width='230'>&nbsp;&nbsp;&nbsp;&nbsp;111</TD>
<TD bgcolor='#C0C0C0'><center>Reviewed<br><input disabled type='checkbox' name='Reviewed'checked></TD>
<TD><center>Accepted<br><input id='AcceptDenyChrYES' disabled type='checkbox' name='AcceptDenyChrYES' checked></TD>
<TD bgcolor='#C0C0C0'><center>Denied<br><input id="AcceptDenyChrNO" disabled type='checkbox' name='AcceptDenyChrNO'></center></TD>
<TD width='190'><CENTER>Department Chair<br>
<textarea disabled style='background-color: white; font color: black; height:38px;' maxlength='500' cols='22'>Looking good</textarea>
</CENTER></TD></TR>

<!-- REGISTRAR RESULTS -->
<TR bgcolor='lightgrey'><TD width='230'></TD>
<TD bgcolor="#CCCCCC"><center>Reviewed<br><input disabled type='checkbox' name='Reviewed' checked></TD>
<TD><center>Accepted<br><input id='AcceptDenyRegYES' disabled type='checkbox' name='AcceptDenyRegYES'></TD>
<TD bgcolor="#CCCCCC" name='AcceptDenyRegNO'><center>Denied<br><input id="AcceptDenyRegNO" disabled type='checkbox' name='AcceptDenyRegNO' checked></center></TD>
<TD width='190'><CENTER>Registrar Office<br>
<textarea disabled style='background-color: white; font color: black; height:38px;' maxlength='500' name='Prerequisites' cols='22'>What?</textarea>
</CENTER></TD></TR>

<!-- CURRICULUM COMMITTEE RESULTS -->
<TR><TD width='230'></TD>
<TD bgcolor="#C0C0C0"><center>Reviewed<br><input disabled type='checkbox' name='Reviewed' ></TD>
<TD><center>Accepted<br><input id='AcceptDenyCCYES' disabled type='checkbox' name='AcceptDenyCCYES'></TD>
<TD bgcolor="#C0C0C0"><center>Denied<br><input id="AcceptDenyCCNO" disabled type='checkbox' name='AcceptDenyCCNO'></center></TD>
<TD width='190'><CENTER>Curriculum Committee<br>
<textarea disabled style='background-color: white; font color: black; height:38px;' maxlength='500' name='Prerequisites' cols='22'></textarea>
</tbody>

<!-- Bottom of table -->
<TFOOT><TR bgcolor='lightyellow'>
<TD>&nbsp;&nbsp;&nbsp;&nbsp;<a style='text-decoration: none' href='http://localhost/REVISEaddedit.php?Records=111'>
<input disabled type='submit' name="EditRecord" id="EditRecord" value='Edit Record' title='Edit record'></a></TD>
<TD colspan='4'><img src='spacer.jpg'></TD>
</TR>
</TFOOT>

</TABLE>
</div>
</form>
</div>
</body>
</HTML>