473,795 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

for loop for unknown number of fields to validate

I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow ;i++) {
If (eval("!Is_In_F ormat( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.len gth != 6")){
alert("Fund must be 6 digits");
eval("document. forms[0].fund_" + i + ".focus();" )
}
}
Jul 23 '05 #1
6 2166
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow ;i++) {
If (eval("!Is_In_F ormat( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.len gth != 6")){
alert("Fund must be 6 digits");
eval("document. forms[0].fund_" + i + ".focus();" )
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow ;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick
Jul 23 '05 #2
Mick White <mw******@roche ster.rr.com> writes:
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do not
know
how many fund entries there will be...it's expandable to handle each
users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am
using
it for other things).

My problem is with my validate function which I've cut down (oh it
doesn't
work but you can see the direction I am going with it). Is there a better
way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow ;i++) {
If (eval("!Is_In_F ormat( document.forms[0].fund_" + i + ".value,
"dddddd")
|| document.forms[0].fund_" + i + ".value.len gth != 6")){
alert("Fund must be 6 digits");
eval("document. forms[0].fund_" + i + ".focus();" )
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow ;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick


Mick,
Can you explain what you are doing here...I could not get it to work, even
after changing it to check just the one "fund" field they must use.

function validate(){
if(!/^\d{6}$/.test(document. forms[0].fund_1.value){
alert("Fund must be 6 digits");
document.forms[0].fund_1.focus() ;
}
else document.forms[0].submit();
}
Jul 23 '05 #3
Abby Lee <ab*******@hotm ail.com> writes:
Mick White <mw******@roche ster.rr.com> writes:
Abby Lee wrote:
I must confirm the user enters a value for each fund they need. I do
not
know
how many fund entries there will be...it's expandable to handle each
users
needs. I must varify each fund they enter is six digits long. I have no

problems with the Is_In_Format function (I found it on the web and am
using
it for other things).

My problem is with my validate function which I've cut down (oh it
doesn't
work but you can see the direction I am going with it). Is there a
better
way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow ;i++) {
If (eval("!Is_In_F ormat( document.forms[0].fund_" + i + ".value,
"dddddd")
|| document.forms[0].fund_" + i + ".value.len gth != 6")){
alert("Fund must be 6 digits");
eval("document. forms[0].fund_" + i + ".focus();" )
}
}

function validate(){
f-document.forms[0];
for(i=1;i<=nrow ;i++) {
if(f["fund"+i].value){
if(!/^\d{6}$/.test(f["fund"+i].value){
alert("Fund must be 6 digits");
f["fund_" + i].focus();
return false;
}
}
}
return true;
}

I am assuming empty fields are OK.
Mick


Mick,
Can you explain what you are doing here...I could not get it to work, even
after changing it to check just the one "fund" field they must use.

function validate(){
if(!/^\d{6}$/.test(document. forms[0].fund_1.value){
alert("Fund must be 6 digits");
document.forms[0].fund_1.focus() ;
}
else document.forms[0].submit();
}

Nevermind and thank you Mick, I got it working ;)
Jul 23 '05 #4
JRS: In article <ui************ *************** @news.ks.uiuc.e du>, seen
in news:comp.lang. javascript, Abby Lee <ab*******@hotm ail.com> posted at
Mon, 26 Apr 2004 11:08:04 :
I must confirm the user enters a value for each fund they need. I do not know
how many fund entries there will be...it's expandable to handle each users
needs. I must varify each fund they enter is six digits long. I have no
problems with the Is_In_Format function (I found it on the web and am using
it for other things).

My problem is with my validate function which I've cut down (oh it doesn't
work but you can see the direction I am going with it). Is there a better way
to validate this? If not what am I doing wrong?
function validate() {
for(i=1;i<=nrow ;i++) {
If (eval("!Is_In_F ormat( document.forms[0].fund_" + i + ".value, "dddddd")
|| document.forms[0].fund_" + i + ".value.len gth != 6")){
alert("Fund must be 6 digits");
eval("document. forms[0].fund_" + i + ".focus();" )
}
}


Rather than using some dubious function from the Web, why not test
directly with a RegExp /$\d{6}$/ ?

<URL:http://www.merlyn.demo n.co.uk/js-valid.htm#VFF> has a general
method, shown in ...#TC, using an Array in an Object to define all the
tests on a form; it should be possible to replace the scanning of the
array with scanning what I suppose to be an array of elements.

You want something like

function validate() { var F, OK
for(i=0;i<nrow; i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
Dr John Stockton wrote:

<snip>

function validate() { var F, OK
for(i=0;i<nrow; i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

OP states that empty fields are OK. But if there is an entry, it should
be 6 digits.
See my earlier posting.
Mick
Jul 23 '05 #6
JRS: In article <zV************ ********@twiste r.nyroc.rr.com> , seen in
news:comp.lang. javascript, Mick White <mw******@roche ster.rr.com> posted
at Mon, 26 Apr 2004 23:27:27 :
Dr John Stockton wrote:

<snip>

function validate() { var F, OK
for(i=0;i<nrow; i++) { F = document.forms[0].element[i] // or similar
OK = /$\d{6}$/.test(F.value) // 6 digits only
if (!OK) { alert("Fund " + i + " must be 6 digits") ; F.focus() ;
return false } }
return true }

FAQ 4.40, 4.39, of course.

OP states that empty fields are OK. But if there is an entry, it should
be 6 digits.


(a) The first $ above should be ^
(b) OK = /^$|^\d{6}$/.test( ) // seems OK; empty or 6-digit

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13076
by: Bartosz Wegrzyn | last post by:
I use onblue event to validate fields in my form. I do this onblur="return isname()" and so so ... I have one form with 20 fields. My problem is that when the focus is for example on the first field of my form the "name" field and I click somewher or press tab than I loose focus and my isname() function is executed. Everything is fine but the focus was change for next field
6
2871
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and loop through all the forms in a database and pull information about the form (controls and properties). We would need to do the same in our VB.NET project; loop through the project and get the web form's control and property information...
6
7136
by: simina | last post by:
Hi... I have a form with 4 number fields: phone area, phone number, cell area, cell number. I did a function that checks the "number" issue for all 4 fields in the same time (because the code is onBlur: "return ph(this);"). Now the problem is that if the user hits Enter data still goes to the database (of course, because I should have the function called in the form's onSubmit...... But how can I do this because I should now have 4...
8
1693
by: Abby Lee | last post by:
My function works but there has got to be a way to make a for loop to handle this...but I can't get a for loop to work. You can tell, I'm not very good at this...help. "myvalue" is the number of miles the person enters "myitem" is the row...there are seven rows where they can list expenses. "myvalue" * .375 = amount to be reimbursed All the rows are added and placed into the total.
4
13545
by: just.an.imbecile | last post by:
I have searched alot for this and cannot find an answer. I have a simple form, and when it submits, I have it posting the data. I have a simple function to loop through and print out all my form data: <table class="data" width="90%"> <tr> <th>Name</th> <th>Value</th></tr> <% string val;
5
2546
by: eyoung | last post by:
I have a function to check a string to make sure it is 6 digites using the trigger onBlur="CkFrmt(this)" Problem is I've got 4 fields in a row...if I enter a wrong number in the first and hit tab I get the error message and my script tries to move the focus to the first item...but because I hit the tab the focus in already on the second item which does not contain a 6 digit value so I must kill the page. help! function CkFrmt(str) {
4
1688
by: Andy in S. Jersey | last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know how many I should create until runtime. I will be reading a table, and 0,1,2, or more fields have to be put into individual ArrayLists. How do I create an unknown number of ArrayLists? Right now I put all the values into one ArrayList. I know how many fields are in the ArrayList so I then know that every one, or every other one, or
5
5041
by: imailz | last post by:
Hi all, since I'm forced to switch from Fortran to C I wonder if there is posibility in C: 1) to use implicit loops 2) to parse several variables which number is determined at runtime. Following example: The output contains n columns which have to be read in. The number of
0
9672
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
9519
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
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
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();...
1
4113
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
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.