ronaldj
asked on
Problem With A Simple Loop
Loops have always given me a problem...I have the following:
<input type="text" name="text2" value="First Name" readonly size="20" style="color: #FFFFFF; border: 1px solid #FFFFFF;border:1px solid #FFFFFF;background-color:# FFFFFF">
<script LANGUAGE="JavaScript">
function ResetDefaultBeneficiaryTex t() {
array1=new Array(3);
array1[0]="text2";
array1[1]="text3";
array1[2]="text4";
alert("array1 read");
alert("function started")
for (i=0;i<=3;i++) {
alert("loop started");
document.forms[0].array1[i ].style.fo ntWeight=' normal'
alert("fontweight");
document.forms[0].array1[i ].style.ba ckgroundCo lor='white '
alert("BGcolor");
document.forms[0].array1[i ].style.co lor='gray'
alert("color");
}
}
</SCRIPT>
the routine is triggered by a button...once I get to my first document.forms[0] line, the program stops (know this from the alert lines)...thoughts?
Thanks,
Ron
<input type="text" name="text2" value="First Name" readonly size="20" style="color: #FFFFFF; border: 1px solid #FFFFFF;border:1px solid #FFFFFF;background-color:#
<script LANGUAGE="JavaScript">
function ResetDefaultBeneficiaryTex
array1=new Array(3);
array1[0]="text2";
array1[1]="text3";
array1[2]="text4";
alert("array1 read");
alert("function started")
for (i=0;i<=3;i++) {
alert("loop started");
document.forms[0].array1[i
alert("fontweight");
document.forms[0].array1[i
alert("BGcolor");
document.forms[0].array1[i
alert("color");
}
}
</SCRIPT>
the routine is triggered by a button...once I get to my first document.forms[0] line, the program stops (know this from the alert lines)...thoughts?
Thanks,
Ron
Hi ronaldj,
This is a bit confusing. What are you trying to do, and are you showing us the complete code?
Regards,
Zyloch
This is a bit confusing. What are you trying to do, and are you showing us the complete code?
Regards,
Zyloch
Hi
try changing all the lines that use
document.forms[0].array1[i ].style.
to
document.getElementById(ar ray1[i]).s tyle.
You will also need to add an id="text2" as well as name="text2" to each object to ensure cross brower compatiability.
Plus your for loop will get to 3 and your array only goes to 2.
Instead of for (i=0;i<=3;i++) try either for (i=0;i<3;i++) or for (i=0;i<=2;i++)
HTH
Scott
try changing all the lines that use
document.forms[0].array1[i
to
document.getElementById(ar
You will also need to add an id="text2" as well as name="text2" to each object to ensure cross brower compatiability.
Plus your for loop will get to 3 and your array only goes to 2.
Instead of for (i=0;i<=3;i++) try either for (i=0;i<3;i++) or for (i=0;i<=2;i++)
HTH
Scott
ASKER
Maybe this will clear things up a bit...
the following actual routine gets done what's needed for ClientType 1...
<script LANGUAGE="JavaScript"><!--
function RDBT() {
document.forms[0].text1.st yle.fontWe ight='norm al'
document.forms[0].text1.st yle.backgr oundColor= 'white'
document.forms[0].text1.st yle.color= 'gray'
document.forms[0].text2.st yle.fontWe ight='norm al'
document.forms[0].text2.st yle.backgr oundColor= 'white'
document.forms[0].text2.st yle.color= 'gray'
document.forms[0].text3.st yle.fontWe ight='norm al'
document.forms[0].text3.st yle.backgr oundColor= 'white'
document.forms[0].text3.st yle.color= 'gray'
document.forms[0].text4.st yle.fontWe ight='norm al'
document.forms[0].text4.st yle.backgr oundColor= 'white'
document.forms[0].text4.st yle.color= 'gray'
document.forms[0].text5.st yle.fontWe ight='norm al'
document.forms[0].text5.st yle.backgr oundColor= 'white'
document.forms[0].text5.st yle.color= 'gray'
document.forms[0].text6.st yle.fontWe ight='norm al'
document.forms[0].text6.st yle.backgr oundColor= 'white'
document.forms[0].text6.st yle.color= 'gray'
}
//--></SCRIPT>
however, there are also ClientTypes 2...8
thought a loop would ease the burden of Copy/Edit/Paste and be more efficient.
Ron
the following actual routine gets done what's needed for ClientType 1...
<script LANGUAGE="JavaScript"><!--
function RDBT() {
document.forms[0].text1.st
document.forms[0].text1.st
document.forms[0].text1.st
document.forms[0].text2.st
document.forms[0].text2.st
document.forms[0].text2.st
document.forms[0].text3.st
document.forms[0].text3.st
document.forms[0].text3.st
document.forms[0].text4.st
document.forms[0].text4.st
document.forms[0].text4.st
document.forms[0].text5.st
document.forms[0].text5.st
document.forms[0].text5.st
document.forms[0].text6.st
document.forms[0].text6.st
document.forms[0].text6.st
}
//--></SCRIPT>
however, there are also ClientTypes 2...8
thought a loop would ease the burden of Copy/Edit/Paste and be more efficient.
Ron
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this line (beside the missing ';' ), I think won't work because 'array1' is not a member of document.forms[0]