473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
8 1395
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Thomas Matthews | last post by:
Hi, My son is writing a program to move a character. He is using the numbers on the keypad to indicate the direction of movement: 7 8 9 4 5 6 1 2 3 Each number has a direction except...
6
by: deanfamily11 | last post by:
I've set up a case statement to have my program determine where on the Cartesian plane a point the user enters is located. I keep getting the C2051 error when I compile. Any help? #include...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
3
by: birju | last post by:
Hi, I'm running SQL Profiler on an SQL Server 2000 database. I see that one stored procedure gets repeatedly executed having a handle of '1'. This query takes a long time to complete. How do I...
1
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
1
by: Elmo Watson | last post by:
I've inherited a project that has quite a few Table rows - inside each cell, within the row are a couple of textboxes ("in" and "out"), along with a "total" label. Also - this is all within a...
1
by: traceable1 | last post by:
I have a table with a unique non-clustered index on it. It has the IGNORE_DUP_KEY option on. For some reason, I am getting the following error: ...
12
by: Earl Partridge | last post by:
I just downloaded this VB Express. I need a little help in understanding the request for database data, that is the format/syntax compared to an SQL statement. In my SQL I would use a select...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.