473,657 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ar ow.value; i > 1 ; i--){
if (document.RFO.a cct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_i.focus( );
}
}

The problem seems to be with the if statement...I'v e also tried
if (document.RFO.a cct_tot_(i).val ue ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_(i).focu s();
}
Jul 20 '05 #1
8 1406
On Fri, 23 Jan 2004 09:57:13 -0600, <ab*******@hotm ail.com> wrote:
for(i = document.RFO.ar ow.value; i > 1 ; i--){
if (document.RFO.a cct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_i.focus( );
}
}

The problem seems to be with the if statement...I'v e also tried
if (document.RFO.a cct_tot_(i).val ue ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_(i).focu s();
}


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.******@blueyo nder.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.getEle mentById(num)
var stuff;
var arow = num * (-1);
document.RFO.ar ow.value=arow;
document.all.Ac cAmt.style.visi bility="visible ";
document.all.Ac cTot.style.visi bility="visible ";
document.RFO.ac c_tot_1.value=" Balance";
document.RFO.ac c_tot_1.disable d="true";
stuff = "<table><tr ><td width=\"70\"><i nput type=\"text\" size=\"5\"
name=\"fund_" + arow + "\" class=\"regSoft \">"

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

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

stuff = stuff + "</td><td width=\"50\"><i nput 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=\"visibil ty:visible\">"
stuff = stuff + "<A onClick=\"javas cript:addacc(" + num +")\"><u
class=\"regSoft \"><font color=\"blue\"> Add Account</font></u></a></div>"
del1.innerHTML = stuff
}

Michael Winter <M.******@bluey onder.co.invali d> writes:
On Fri, 23 Jan 2004 09:57:13 -0600, <ab*******@hotm ail.com> wrote:
for(i = document.RFO.ar ow.value; i > 1 ; i--){
if (document.RFO.a cct_tot_i.value ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_i.focus( );
}
}

The problem seems to be with the if statement...I'v e also tried
if (document.RFO.a cct_tot_(i).val ue ==""){
alert("Need Amount For Each Account Used");
document.RFO.ac ct_tot_(i).focu s();
}


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*******@hotm ail.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.******@blueyo nder.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="visibili ty:hidden">Amou nt</div></td>
</tr>
</table>
<table>
<tr>
<td width="70"><sel ect name="fund_1" class="regSoft" >
<option></option>
<option>25100 3</option> //500 options deleted
</select>
</td>
<td width="70"><sel ect name="org_1" class="regSoft" >
<option></option>
<option>32000 0</option>
</select>
</td>
<td width="70"><sel ect name="program_1 " class="regSoft" >
<option></option>
<option>19110 0</option>
</select>
</td>
<td width="50"><sel ect name="activity_ 1" class="regSoft" >
<option></option>
<option>A00</option>
</select>
</td>
<td width="70"><div id="AccTot" style="visibili ty: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="visibili ty:visible"> <a onClick=javascr ipt:addacc(-2)
<u class="regSoft" ><font color="blue">Ad d Account</font></u></a> </div>
<p>&nbsp;</p>
<table width="100%" border="0" cellspacing="4" cellpadding="0" >
<tr>
<td colspan="2"><in put name="liquor" type="checkbox"
class="regSoft" value="yes">
<span class="regHard" >Liquor Purchased?</span></td>
</tr>
<tr>
<td colspan="2"><in put name="deadline" type="checkbox"
class="regSoft" value="yes">
<span class="regHard" >Special Deadline?</span> <SPACER> <input
name="deadline_ date" onBlur="thedead line()" type="text" class="regSoft"
size="8"></td>
</tr>
</table>
</div>
</table>

Michael Winter <M.******@bluey onder.co.invali d> writes:
On Fri, 23 Jan 2004 11:38:32 -0600, <ab*******@hotm ail.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.a cct_tot_" + i + ".value == ''"

Michael Winter <M.******@bluey onder.co.invali d> writes:
On Fri, 23 Jan 2004 11:38:32 -0600, <ab*******@hotm ail.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*******@hotma il.com writes:
Michael Winter <M.******@bluey onder.co.invali d> 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.a cct_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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
ab*******@hotma il.com writes:
Michael Winter <M.******@bluey onder.co.invali d> 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.a cct_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*******@hotma il.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/rasterTriangleD OM.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
8331
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 for '5'. So in his switch statement, he omits a case for '5':
6
4695
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 <iomanip> #include <iostream> using namespace std;
10
2684
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 won. At first it looked like it was working, but now it sometimes assigns a win when you enter an X or O (doesn't matter) on certain tiles (row 1, column 1 won't be an error, but row 2, column 3 will be...). If you can find the problem, I'd be...
4
5600
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 = '" & request.form(strSerialNum) & "', " sql01 = sql01 & "Description = '" & request.form(strDesc) & "', " sql01 = sql01 & "Location = '" & request.form(strLoc) & "', "
3
7314
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 find what the text of the stored procedure is? I cant see any handle being created (using sp_prepare) with an id of '1' in the profiler. Is there any way to force the server to re-prepare all statements so that I can see the statement text and its...
1
1582
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 work " .mysql_insert_id(); and not any other php or mysql error to tell me if anything is wrong the insert statment. To top it up, I have an echo statment of the insert statment before it executes, when I copy and paste the insert statment from...
1
8555
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 Content Page/Master Page scenario - I've got the function inside the Content page, along with the all the items herein On each row, each of the in and out and total controls have a number associated with them, like:
1
4417
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: ----------------------------------------------------------------------------- System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object 'dbo.table1 with unique index 'IX_table1'. Duplicate key was ignored.
12
1096
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 statement... example select LastName from Members where month(Birthday) = month(now) How would this be coded in VB Express? Earl
0
8394
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.