Reply
Old 05-08-2006, 10:52 AM loop
Skilled Talker

Posts: 95
I'm looking for help.

I have 5 fields on a form that i'm reading in as

var yr1cost = Form1.yr1Cost.value;
var yr2cost = Form1.yr2Cost.value;
var yr3cost = Form1.yr3Cost.value;
var yr4cost = Form1.yr4Cost.value;
var yr5cost = Form1.yr5Cost.value;

i know what to loop through these and check to see if there are null

for example

i = 0
do while 1<4
if

----------------------------------------------------------------------------------------------------------

I'm looking for help.

I have 5 fields on a form that i'm reading in as

var yr1cost = Form1.yr1Cost.value;
var yr2cost = Form1.yr2Cost.value;
var yr3cost = Form1.yr3Cost.value;
var yr4cost = Form1.yr4Cost.value;
var yr5cost = Form1.yr5Cost.value;

i know what to loop through these and check to see if there are null

for example

i = 0
do while 1<4
if field null then display error
if field is 0 > greater then do something else
loop

my problem is i do not know how to loop throught the different fileds
i cant go from yr1cost to yr2cost
automatically
higginbt is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-08-2006, 11:28 AM Re: loop
funkdaddu's Avatar
Web Design Snob

Posts: 636
something like this:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function calc() {
	var yrcost = new Array;
	var missing = new Array;
	
	for (i=1;i<=5;i++) {
		if (eval("Form1.yr" + i + "Cost.value") == "") {
			missing.push(i);
		}
	}
	if (missing[0]) {
		alert("Please fill in the follwing Costs: " + missing);
		return false;
	} else {
		return true;
	}
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="Form1" action="" method="get" name="Form1" onsubmit="return calc();">
			<input type="text" name="yr1Cost" value="234" size="24">
			<p><input type="text" name="yr2Cost" value="" size="24"></p>
			<p><input type="text" name="yr3Cost" value="55" size="24"></p>
			<p><input type="text" name="yr4Cost" value="" size="24"></p>
			<p><input type="text" name="yr5Cost" value="7778" size="24"></p>
			<p><input type="submit" name="submitButtonName"></p>
		</form>
		<p></p>
	</body>

</html>
Eval is not the best way to cycle through, but I didn't want to change your field names. I usually add "req_" to te beginning of required fields, then check the entire form for fields starting with that and then check for null values.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-09-2006, 06:36 AM Re: loop
Skilled Talker

Posts: 95
Yeah, THanks i did it the same way by reading it into an array to start with

Quote:
var description = Form1.txtDesc.value
var CostArray=new Array()
CostArray[0]=Form1.yr1Cost.value
CostArray[1]=Form1.yr2Cost.value
CostArray[2]=Form1.yr3Cost.value
CostArray[3]=Form1.yr4Cost.value
CostArray[4]=Form1.yr5Cost.value

while (j<=4)
{
if (IsNumeric(CostArray[j])!=true)
{
numcount = numcount+1

}

j=j+1
}
higginbt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to loop
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11300 seconds with 13 queries