Solved

Problem With A Simple Loop

Posted on 2004-10-02
5
209 Views
Last Modified: 2010-04-17
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 ResetDefaultBeneficiaryText() {
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.fontWeight='normal'
  alert("fontweight");
document.forms[0].array1[i].style.backgroundColor='white'
  alert("BGcolor");
document.forms[0].array1[i].style.color='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
0
Comment
Question by:ronaldj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12208589
document.forms[0].array1[i].style.fontWeight='normal'

this line (beside the missing ';' ), I think won't work because 'array1' is not a member of document.forms[0]
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12208605
Hi ronaldj,

This is a bit confusing. What are you trying to do, and are you showing us the complete code?

Regards,
Zyloch
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12208606
Hi

try changing all the lines that use

document.forms[0].array1[i].style.

to

document.getElementById(array1[i]).style.

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
0
 

Author Comment

by:ronaldj
ID: 12208677
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.style.fontWeight='normal'
document.forms[0].text1.style.backgroundColor='white'
document.forms[0].text1.style.color='gray'
document.forms[0].text2.style.fontWeight='normal'
document.forms[0].text2.style.backgroundColor='white'
document.forms[0].text2.style.color='gray'
document.forms[0].text3.style.fontWeight='normal'
document.forms[0].text3.style.backgroundColor='white'
document.forms[0].text3.style.color='gray'
document.forms[0].text4.style.fontWeight='normal'
document.forms[0].text4.style.backgroundColor='white'
document.forms[0].text4.style.color='gray'
document.forms[0].text5.style.fontWeight='normal'
document.forms[0].text5.style.backgroundColor='white'
document.forms[0].text5.style.color='gray'
document.forms[0].text6.style.fontWeight='normal'
document.forms[0].text6.style.backgroundColor='white'
document.forms[0].text6.style.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
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 125 total points
ID: 12208685
Ah I see. You mean like this:

document.forms[0].elements[array1[i]].style.fontWeight='normal'
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question