467,076 Members | 995 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

If statement within For statment keeps getting error

User enters account number
if another account number is needed
User clicks add account which creates another row

When validating when they hit submit I want to check to make sure they tell
us how much money to charge to all account numbers except the first one (all
remaining money goes on the first account number)
within the header script:

for(i = document.RFO.arow.value; i > 1 ; i--){
if (document.RFO.acct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_i.focus();
}
}

The problem seems to be with the if statement...I've also tried
if (document.RFO.acct_tot_(i).value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_(i).focus();
}
Jul 20 '05 #1
  • viewed: 1218
Share:
8 Replies
On Fri, 23 Jan 2004 09:57:13 -0600, <ab*******@hotmail.com> wrote:
for(i = document.RFO.arow.value; i > 1 ; i--){
if (document.RFO.acct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_i.focus();
}
}

The problem seems to be with the if statement...I've also tried
if (document.RFO.acct_tot_(i).value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_(i).focus();
}


Try:

if( '' == document.forms['RFO'].elements['acct_tot_' + i].value ) {
alert( 'Need amount for each account used.' );
document.forms['RFO'].elements['acct_tot_' + i].focus();
}

The 'if' expression could also be written

if( !document.forms['RFO'].elements['acct_tot_' + i].value ) {

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2

Thanks Michael, but that doesn't work either...it's like my script can't
detect any account elements except the first one. I've been trying to get
access to the information for other scripts and can't...the only thing I can
do is collect the information after the page has been submitted.

I use the follow script to create text boxes when a person wants to add an

function addacc(num) {
var del1 = document.getElementById(num)
var stuff;
var arow = num * (-1);
document.RFO.arow.value=arow;
document.all.AccAmt.style.visibility="visible";
document.all.AccTot.style.visibility="visible";
document.RFO.acc_tot_1.value="Balance";
document.RFO.acc_tot_1.disabled="true";
stuff = "<table><tr><td width=\"70\"><input type=\"text\" size=\"5\"
name=\"fund_" + arow + "\" class=\"regSoft\">"

stuff = stuff + "</td><td width=\"70\"><input type=\"text\" size=\"5\"
name=\"org_" + arow + "\" class=\"regSoft\">"

stuff = stuff + "</td><td width=\"70\"><input type=\"text\" size=\"5\"
name=\"program_" + arow + "\" class=\"regSoft\">"

stuff = stuff + "</td><td width=\"50\"><input type=\"text\" size=\"2\"
name=\"activity_" + arow + "\" class=\"regSoft\">"

stuff = stuff + "</td><td width=\"70\">"
stuff = stuff + "<input name=\"acc_tot_" + arow + "\" type=\"text\"
class=\"regSoft\" size=\"5\">"
stuff = stuff + "</td></tr></table>"

num = num - 1;

stuff = stuff + "<div id=\"" + num + "\" style=\"visibilty:visible\">"
stuff = stuff + "<A onClick=\"javascript:addacc(" + num +")\"><u
class=\"regSoft\"><font color=\"blue\">Add Account</font></u></a></div>"
del1.innerHTML = stuff
}

Michael Winter <M.******@blueyonder.co.invalid> writes:
On Fri, 23 Jan 2004 09:57:13 -0600, <ab*******@hotmail.com> wrote:
for(i = document.RFO.arow.value; i > 1 ; i--){
if (document.RFO.acct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_i.focus();
}
}

The problem seems to be with the if statement...I've also tried
if (document.RFO.acct_tot_(i).value ==""){
alert("Need Amount For Each Account Used");
document.RFO.acct_tot_(i).focus();
}


Try:

if( '' == document.forms['RFO'].elements['acct_tot_' + i].value ) {
alert( 'Need amount for each account used.' );
document.forms['RFO'].elements['acct_tot_' + i].focus();
}

The 'if' expression could also be written

if( !document.forms['RFO'].elements['acct_tot_' + i].value ) {

Mike

Jul 20 '05 #3
On Fri, 23 Jan 2004 11:38:32 -0600, <ab*******@hotmail.com> wrote:
Thanks Michael, but that doesn't work either...it's like my script can't
detect any account elements except the first one. I've been trying to get
access to the information for other scripts and can't...the only thing I
can do is collect the information after the page has been submitted.


Could you show an example of the HTML that results from your script? A URL
would be fine.

Assuming that acc_tot_n exists in the form RFO,
document.forms['RFO'].elements['acc_tot_' + n] should work.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4
Actually, the html only shows the first (hard coded) account text
boxes...even though you can see them on the web page and they transfer fine,
the source code shows nothing.
The first set of text boxes are select option boxes...all additional text
boxes created are plan text boxes.

I remember getting to this information once...had to do some strange
code...but now I forget how I did it.

after adding a second acct number the source code looks like

<table>
<table>
<tr>
<td width="70" class="regHard">Fund</td>
<td width="70" class="regHard">Org</td>
<td width="70" class="regHard">Program</td>
<td width="50" class="regHard">Activity</td>
<td width="70" class="regHard"><div id="AccAmt"
style="visibility:hidden">Amount</div></td>
</tr>
</table>
<table>
<tr>
<td width="70"><select name="fund_1" class="regSoft">
<option></option>
<option>251003</option> //500 options deleted
</select>
</td>
<td width="70"><select name="org_1" class="regSoft">
<option></option>
<option>320000</option>
</select>
</td>
<td width="70"><select name="program_1" class="regSoft">
<option></option>
<option>191100</option>
</select>
</td>
<td width="50"><select name="activity_1" class="regSoft">
<option></option>
<option>A00</option>
</select>
</td>
<td width="70"><div id="AccTot" style="visibility:hidden">
// Hidden until a second account is needed
<input name="acc_tot_1" type="text" size="5" class="regSoft">
</div>
</td>
</tr>
</table>
// Create a new account
</div>
<div id="-2" style="visibility:visible"> <a onClick=javascript:addacc(-2)
<u class="regSoft"><font color="blue">Add Account</font></u></a> </div>
<p>&nbsp;</p>
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td colspan="2"><input name="liquor" type="checkbox"
class="regSoft" value="yes">
<span class="regHard">Liquor Purchased?</span></td>
</tr>
<tr>
<td colspan="2"><input name="deadline" type="checkbox"
class="regSoft" value="yes">
<span class="regHard">Special Deadline?</span> <SPACER> <input
name="deadline_date" onBlur="thedeadline()" type="text" class="regSoft"
size="8"></td>
</tr>
</table>
</div>
</table>

Michael Winter <M.******@blueyonder.co.invalid> writes:
On Fri, 23 Jan 2004 11:38:32 -0600, <ab*******@hotmail.com> wrote:
Thanks Michael, but that doesn't work either...it's like my script can't
detect any account elements except the first one. I've been trying to get
access to the information for other scripts and can't...the only thing I
can do is collect the information after the page has been submitted.


Could you show an example of the HTML that results from your script? A URL
would be fine.

Assuming that acc_tot_n exists in the form RFO,
document.forms['RFO'].elements['acc_tot_' + n] should work.

Mike

Jul 20 '05 #5
Thanks for your help Michael.

found something that works....
"document.RFO.acct_tot_" + i + ".value == ''"

Michael Winter <M.******@blueyonder.co.invalid> writes:
On Fri, 23 Jan 2004 11:38:32 -0600, <ab*******@hotmail.com> wrote:
Thanks Michael, but that doesn't work either...it's like my script can't
detect any account elements except the first one. I've been trying to get
access to the information for other scripts and can't...the only thing I
can do is collect the information after the page has been submitted.


Could you show an example of the HTML that results from your script? A URL
would be fine.

Assuming that acc_tot_n exists in the form RFO,
document.forms['RFO'].elements['acc_tot_' + n] should work.

Mike

Jul 20 '05 #6
ab*******@hotmail.com writes:
Michael Winter <M.******@blueyonder.co.invalid> writes:
Assuming that acc_tot_n exists in the form RFO,
document.forms['RFO'].elements['acc_tot_' + n] should work.

Thanks for your help Michael.

found something that works....
"document.RFO.acct_tot_" + i + ".value == ''"


That doesn't work, at least on its own. You then have to use "eval" to
make it work, which is a *very* bad idea. I suggest you follow
Michael's advice instead, and forget you ever heard about eval. Your
code will be better for ir.

/L 'and please don't top post'
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Lasse Reichstein Nielsen <lr*@hotpop.com> writes:
ab*******@hotmail.com writes:
Michael Winter <M.******@blueyonder.co.invalid> writes:

Assuming that acc_tot_n exists in the form RFO,
document.forms['RFO'].elements['acc_tot_' + n] should work.

Thanks for your help Michael.

found something that works....
"document.RFO.acct_tot_" + i + ".value == ''"


That doesn't work, at least on its own. You then have to use "eval" to
make it work, which is a *very* bad idea. I suggest you follow
Michael's advice instead, and forget you ever heard about eval. Your
code will be better for ir.

/L 'and please don't top post'


Why, what's wrong with using eval...seems to be working fine.
Jul 20 '05 #8
ab*******@hotmail.com writes:
Why, what's wrong with using eval...seems to be working fine.


The FAQ says:
<URL:http://jibbering.com/faq/#FAQ4_40>
The reason is that eval
1) inefficient (very)
2) failure prone - syntax errors are not caught when the program is
parsed like normally, but only when the eval is run, which makes it
harder to spot errors and debug them
3) so easy to avoid by using the normal language constructs, that
there is no positive reason to use it that can outweigh the above two.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by Thomas Matthews | last post: by
6 posts views Thread by deanfamily11 | last post: by
10 posts views Thread by ale.of.ginger@gmail.com | last post: by
3 posts views Thread by birju | last post: by
1 post views Thread by zeebiggie | last post: by
12 posts views Thread by Earl Partridge | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.