Automatically altering text on buttons

L

liglin

Hi,

I would like this script to show a red question mark for each of the
two buttons of a row if after a button click NOK shows and "Try again
WITH colors" is clicked, instead of one. I need both question marks of
the 2 buttons in a row in red, if NOK shows and that button is clicke
and then "Try again WITH colors" is clicked.

In the snippet below

else
{
for(i=0;i<te.length;i++) {te.style.color='black';}
}
// setting caption to ' ? ' for all buttone that contain
btnModuleName
for(i=0;i<te.length;i++) {
if(te.name.match('btnModuleName_' + suffix)) {
if ((te.value.match('OK')) && colors) {
te.style.color = 'red'; }
te.value=' ? ';
}
}
}


I tried to change
te.style.color

to te[i-1].style.color te[i-2].style.color

but that didn't work.


Could anyone help with this?

Thanks, Penelope






<HTML>

<HEAD>

<SCRIPT language="JavaScript">
<!--
function changeColor(objText, objButton)
{
var toggle = objButton.value == " Show solution ";
document.getElementById(objText).style.color = toggle ? "black" :
"#ffccff";

objButton.value = toggle ? "Hide solution" : " Show solution
";
}

function OK(objButton){
objButton.style.color ='black';
objButton.value=' OK ';
}

function NOK(objButton){
objButton.style.color ='black';
objButton.value='NOK';
}

// one function per button set
function ResetButtons_A1(suffix, TheForm,colors){
te=TheForm.elements;
if(colors){
lita=0;
for(i=0;i<te.length;i++) {
if (!te.name.match('btnModuleName_' + suffix)) {
continue; }
if(te.value=='NOK') lita=1;
if(te.value==' Show solution ' && lita==1) {
te[i-1].style.color='red';
te[i-2].style.color='red';
lita=0;
}
}
}
else
{
for(i=0;i<te.length;i++) {te.style.color='black';}
}
// setting caption to ' ? ' for all buttone that contain
btnModuleName
for(i=0;i<te.length;i++) {
if(te.name.match('btnModuleName_' + suffix)) {
if ((te.value.match('OK')) && colors) {
te.style.color = 'red'; }
te.value=' ? ';
}
}
}
//-->

</SCRIPT>


</HEAD>
<FORM name="form" METHOD="post" ACTION="Io00Cellc02.cfm"><TABLE
WIDTH="100%">
<!--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --->
<!--- ========================================================== --->
<!--- This table row is used for the didactic units ---> <TR> <TD
bgcolor="#660099">
<TABLE width="100%" cellspacing="0" cellpadding="5" border="0"> <TR
bgcolor="FFFFDD">
<TD align="left" bgcolor="FFCCFF">
<!--- Multiple choice table starts here --->
First table
<table align="center" width="100%" border="0" bgcolor="#000099"
cellpadding="0" cellspacing="0">
<TR>
<TD width="100%" align="center"> <table width="100%" border="0"
cellpadding="5" cellspacing="1">
<TR bgcolor="FFCCFF"> <TD width="889" valign="top">&nbsp;</TD><TD
width="68" align="center">
<div align="center"><b>Yes</b></div></TD><TD width="65" align="center">
<div align="center"><b>No</b></div></TD><TD width="88">&nbsp;</TD></TR>
<TR bgcolor="FFCCFF"> <TD width="889" valign="top"><FONT size="+1"
color="#ffccff" id=txtModuleName_A1_1>answer1</FONT></TD><TD width="88"
align="center">
<INPUT type="button" value=" ? " onClick="OK(this)"
name="btnModuleName_A1_1">
</TD><TD width="88" align="center"> <INPUT type="button" value=" ?
" onClick="NOK(this)" name="btnModuleName_A1_2">
</TD><TD width="88"> <INPUT type="button" name="ToggleSolution_A1"
value=" Show solution "
onClick="changeColor('txtModuleName_A1_1', this)">
</TD></TR> <TR bgcolor="FFCCFF"> <TD width="889" valign="top"><FONT
size="+1" color="#ffccff" id=txtModuleName_A1_2>answer2</FONT></TD><TD
width="88" align="center">
<INPUT type="button" value=" ? " onClick="NOK(this)"
name="btnModuleName_A1_3">
</TD><TD width="88" align="center"> <INPUT type="button" value=" ?
" onClick="OK(this)" name="btnModuleName_A1_4">
</TD><TD width="88"> <INPUT type="button" name="ToggleSolution_A1"
value=" Show solution "
onClick="changeColor('txtModuleName_A1_2', this)">
</TD></TR> </TABLE></TD></TR> </TABLE><!--- Multiple choice table ends
here --->
<P align = "center"> <INPUT type="button" name="btnAgain" value="Try
again without colors" onClick="ResetButtons_A1 ('A1',this.form)">
<INPUT TYPE="button" NAME="btnAgain2" VALUE="Try again WITH colors"
ONCLICK="ResetButtons_A1 ('A1',this.form,1)"></P></TD></TR>
</TABLE></TD></TR>
<TR> <TD > <BR> </TD></TR>
</TABLE>
<P>Another table here:</P>
<TABLE WIDTH="100%">
<!--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --->
<!--- ========================================================== --->
<!--- This table row is used for the didactic units ---> <TR> <TD
bgcolor="#660099">
<TABLE width="100%" cellspacing="0" cellpadding="5" border="0"> <TR
bgcolor="FFFFDD">
<TD align="left" bgcolor="FFCCFF">
<!--- Multiple choice table starts here --->
Second table
<table align="center" width="100%" border="0" bgcolor="#000099"
cellpadding="0" cellspacing="0">
<TR>
<TD width="100%" align="center">
<table width="100%" border="0" cellpadding="5" cellspacing="1">
<TR bgcolor="FFCCFF">
<TD width="889" valign="top">&nbsp;</TD><TD width="68" align="center">
<div align="center"><b>Yes</b></div></TD><TD width="65" align="center">
<div align="center"><b>No</b></div></TD><TD width="88">&nbsp;</TD></TR>
<TR bgcolor="FFCCFF"> <TD width="889" valign="top"><FONT size="+1"
color="#ffccff" id=txtModuleName_A2_1>answer1</FONT></TD><TD width="88"
align="center">
<INPUT type="button" value=" ? " onClick="OK(this)"
name="btnModuleName_A2_1">
</TD><TD width="88" align="center"> <INPUT type="button" value=" ?
" onClick="NOK(this)" name="btnModuleName_A2_2">
</TD><TD width="88"> <INPUT type="button" name="ToggleSolution_A1"
value=" Show solution "
onClick="changeColor('txtModuleName_A2_1', this)">
</TD></TR> <TR bgcolor="FFCCFF"> <TD width="889" valign="top"><FONT
size="+1" color="#ffccff" id=txtModuleName_A2_2>answer2</FONT></TD><TD
width="88" align="center">
<INPUT type="button" value=" ? " onClick="NOK(this)"
name="btnModuleName_A2_3">
</TD><TD width="88" align="center"> <INPUT type="button" value=" ?
" onClick="OK(this)" name="btnModuleName_A2_4">
</TD><TD width="88"> <INPUT type="button" name="ToggleSolution_A2"
value=" Show solution "
onClick="changeColor('txtModuleName_A2_2', this)">
</TD></TR> </TABLE></TD></TR> </TABLE><!--- Multiple choice table ends
here --->
<P align = "center"> <INPUT type="button" name="btnAgain" value="Try
again without colors" onClick="ResetButtons_A1 ('A2',this.form)">
<INPUT TYPE="button" NAME="btnAgain2" VALUE="Try again WITH colors"
ONCLICK="ResetButtons_A1 ('A2',this.form,1)"></P></TD></TR>
</TABLE></TD></TR>
<TR> <TD > <BR> </TD></TR>
</TABLE>
<P>&nbsp;</P>
</FORM>
</BODY>

</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top