Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array.length not returning the correct value

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a (Coldfusion) document that has a dynamic number of small data entry forms. I'm trying to write code to populate one of the text inputs based on data entered in the first form.

I just started writing the javascript and before writing my iteration code (function PopulateBardoce) I tested the iteration count in an alert. My test document definitely has 25 forms, yet, the alert is displaying 23?

I'm stumped on this one, any help appreciated.

I always try not to dump all my code when asking for help but I think I may have to on this one.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
	<title>OHRC Specimen Card</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<cfparam name="Session.TestBarn.HowManyCards" default="25">
<cfinclude template="security.cfm">
<cfquery name="TrackList" datasource="TestBarn">
	Select description
	From Track
	Where code='#Session.TestBarn.Track#'
</cfquery>
<cfquery name="GetCardCount" datasource="Testbarn">
	Select id
	From Cards
	Where RaceDate=<cfqueryparam value="#CreateODBCDate(Session.TestBarn.RaceDate)#" cfsqltype="CF_SQL_DATE">
	And Track=<cfqueryparam value="#Session.TestBarn.Track#" cfsqltype="CF_SQL_CHAR">
	And Box=<cfqueryparam value="#Session.TestBarn.box#" cfsqltype="CF_SQL_CHAR">
	And Seal=<cfqueryparam value="#Session.TestBarn.seal#" cfsqltype="CF_SQL_CHAR">
</cfquery>
<cfset Session.TestBarn.HowManyCards=Max(Session.TestBarn.HowManyCards,GetCardCount.RecordCount)>
<br>
<cfoutput>
	<table class="Binkleytable" align="center" cellpadding="0" cellspacing="0">
		<cfloop from="1" to="#Session.TestBarn.HowManyCards#" index="i">
			<cfquery name="GetCard" datasource="Testbarn">
				Select id, RaceDate, BarCode, BloodDrug, Urine, Salix, Procaine, 
				Horse, Tattoo, Race, Finish, Color, Sex, Age, Trainer, Owner, 
				WitnessName, WitnessBy, SampledBy, Notes, Blood
				From Cards
				Where RaceDate=<cfqueryparam value="#CreateODBCDate(Session.TestBarn.RaceDate)#" cfsqltype="CF_SQL_DATE">
				And Track=<cfqueryparam value="#Session.TestBarn.Track#" cfsqltype="CF_SQL_CHAR">
				And Box=<cfqueryparam value="#Session.TestBarn.box#" cfsqltype="CF_SQL_CHAR">
				And Seal=<cfqueryparam value="#Session.TestBarn.seal#" cfsqltype="CF_SQL_CHAR">
				And Page=<cfqueryparam value="#i#" cfsqltype="CF_SQL_CHAR">
			</cfquery>
			<tr>
				<td class="ColumnHeadingCell">
					Page #i#
				</td>
			</tr>
			<tr>
				<td class="NormalCell" align="center" valign="middle">
					<form name="Cards" id="Cards" method="post" action="PrintCard.cfm" target="_blank" onsubmit="DisplaySaved(this,'Saved#i#');">
						<input name="PageNumber" type="Hidden" value="#i#">
						<input name="TrackDescription" type="Hidden" value="#TrackList.Description#">
						<table align="center" class="BinkleyTable" width="100%">
							<tr>
								<td class="DataLabel" colspan="3">
									Date: #DateFormat(Session.TestBarn.RaceDate,'mm/dd/yyyy')# &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note: <input name="Notes" size="10" maxlength="50" type="Text" value="#GetCard.Notes#">
								</td>
								<td class="DataLabel" colspan="2">
									<div align="right">
										Sample Number: <input name="BarCode" size="10" value="#GetCard.BarCode#">
										<cfif Not GetCard.RecordCount And i is 1>
											<input type="Button" value="Barcode" [COLOR=red]onclick="PopulateBardoce(this)[/color];">
										</cfif>
									</div>
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="1">
									Blood/Drug: <input name="BloodDrug" type="Checkbox" <cfif GetCard.RecordCount and GetCard.BloodDrug>checked="checked"</cfif>>
								</td>
								
								<td class="DataLabel" colspan="1">
									Urine: <input name="Urine" type="Checkbox"<cfif GetCard.RecordCount and GetCard.Urine>checked="checked"</cfif>>
								</td>
								<td class="DataLabel" colspan="1">
									Salix: <input name="Salix" type="Checkbox"<cfif GetCard.RecordCount and GetCard.Salix>checked="checked"</cfif>>
								</td>
								<td class="DataLabel" colspan="1">
									<div align="right">Procaine: <input name="Procaine" type="Checkbox"<cfif GetCard.RecordCount and GetCard.Procaine>checked="checked"</cfif>></div>
								</td>
								<td class="DataLabel" colspan="1">
									<cfif GetCard.RecordCount>
										<div align="right">Blood: <input name="Blood" type="Checkbox" <cfif GetCard.Blood>checked="checked"</cfif>></div>
									<cfelse>
										<div align="right">Blood: <input name="Blood" type="Checkbox" checked="checked"></div>
									</cfif>
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="2">
									Horse: <input name="Horse" size="20" maxlength="50" value="#GetCard.Horse#">
								</td>
								<td class="DataLabel">
									&nbsp;
								</td>
								<td class="DataLabel" colspan="2">
									<div align="right">Tattoo: <input name="tattoo" size="15" value="#GetCard.tattoo#"></div>
								</td>
							</tr>
							<tr>
								<td class="DataLabel">
									Race: <input name="Race" size="2" value="#GetCard.Race#">
								</td>
								<td class="DataLabel">
									Finish: <input name="Finish" size="2" value="#GetCard.Finish#">
								</td>
								</td>
								<td class="DataLabel">
									Color: <input name="Color" size="6" value="#GetCard.Color#" maxlength="12">
								</td>
								<td class="DataLabel">
									Sex: <input name="Sex" size="2" value="#GetCard.Sex#">
								</td>
								<td class="DataLabel">
									<div align="right">Age: <input name="Age" size="2" value="#GetCard.Age#"></div>
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="2">
									Trainer: <input name="Trainer" size="25" maxlength="50" value="#GetCard.Trainer#">
								</td>
								<td class="DataLabel">
									&nbsp;
								</td>
								<td class="DataLabel" colspan="2">
									<div align="right">Track: #TrackList.Description#</div>
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="5">
									Owner: <input name="Owner" size="50" value="#GetCard.Owner#">
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="3">
									Witness Name: <input name="WitnessName" size="50" value="#GetCard.WitnessName#">
								</td>
								<td class="DataLabel" colspan="2">
									Witness By: <input name="WitnessBy" size="50" value="#GetCard.WitnessBy#">
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="5">
									Sampled By: <input name="SampledBy" size="50" value="#GetCard.SampledBy#">
								</td>
							</tr>
							<tr>
								<td class="DataLabel" colspan="5">
									<div align="center"><input type="Submit" value="Print/Save Card">&nbsp;
										<span id="Saved#i#" style="color: red;">
											<cfif Trim(GetCard.WitnessName) gt '' and Trim(GetCard.WitnessBy) gt '' and Trim(GetCard.SampledBy) gt ''>
												Saved
											</cfif>
										</span>
									</div>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</cfloop>
	</table>
</cfoutput>
<body>
</body>
</html>

<script type="text/javascript" language="JavaScript">
	
	function trim(t) {
 	   return t.replace( /^\s+/, "" ).replace( /\s+$/, "" );
	}
	
	[COLOR=red]function PopulateBardoce() [/color]{
		if (trim(document.Cards[0].BarCode.value) == "" ) {
			//alert("Cannot Populate with and Empty Barcode");
		}
		[COLOR=red]alert(document.Cards[0].length);[/color]
	}
	
	function DisplaySaved(Currentfrm,CurrentIteration){
		if (trim(Currentfrm.WitnessName.value) != "" && trim(Currentfrm.WitnessBy.value) != "" && trim(Currentfrm.SampledBy.value) != "") {
			objSpan=document.getElementById(CurrentIteration);
			objSpan.innerHTML='Saved';
		}
	}
	
</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Hi

Please post the generated HTML, not the server-side code. Use your browser's View Source command and paste what you can see there. ( You can cut off the decorations and irrelevant parts. )

Feherke.
 
I got it!

document.Cards[0].length retuns the number of elements in that form.

document.Cards.length returns the number of form elements named Cards...

hope this helps someone else.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
This shouldn't have an bearing on your issue but....

<input type="Button" value="Barcode" onclick="PopulateBardoce(this);" [red]/[/red]>

need / to properly close the input
 
Thanks, I will.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top