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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a form field with a database table where it is calculated now.

Status
Not open for further replies.

LohneB

Programmer
May 4, 2000
84
US
I could use some help - I haven't been able to find any similar problems in my searches.

I have an application that is written in both Cold Fusion and Javascript. I do a query using CF code to obtain values for a series of fields on a form that are currently being calculated using data from other fields on the form. The objective is to place fixed, preloaded data in the select fields rather than use the calculated values.

The query is:

*********************************************************
*********************************************************
<cfquery name="past_bl" datasource="PRIME">
SELECT st_hr,
stlabor_l,
plc_cd
FROM TABLE_SUB
WHERE prjid='#url.prj#'
AND rev='#url.rev#'
AND ver='#url.ver#'
AND contract_id=#contract#
AND cnt_yr='#url.cyr#'
AND plc_cd = '999999'
AND st_hr > 0
AND baseline = 'N'
</cfquery>
<cfset blcount = past_bl.recordcount>
<script language="JavaScript">
bl = new Array()
alert("count is <cfoutput>#blcount#</cfoutput>")
<cfloop index = Cnt from = "1" to = #blcount#>
alert("Value is <cfoutput>#past_bl.stlabor_l[Cnt]#</cfoutput> - placed in array.")
</cfloop>
</script>
******************************************************
******************************************************

In the sample I'm working on, I have two values from the table - 245516 dollars and 281232 dollars. These represent forecasted dollars for CY1 and CY2 (CY id contract year - where CY3 is the current year.)

The code area where I'm trying to add the code to place these two values in their appropriate columns is:

********************************************************
********************************************************
// Calculate labor cost and FTEs based on number of hours entered. The logic to control prior and out years relative to the current year call this function with passed parameters - cyr and row.
function calcOutYearLaborFromHours (cyr, row)
{
hoursName = 'document.TheForm.labHoursOtherCyTot'+cyr+'_'+row
fteName = 'document.TheForm.aveFteOtherCyTot'+cyr+'_'+row
costName = 'document.TheForm.labCostOtherCyTot'+cyr+'_'+row

if(rateType == 'M3')
{
labor000 = m3RateByRow[row][cyr-1] * Number(eval(hoursName).value); // this calculation is OK
}
else // rateType is 'J5'
{
labor000 = j5RateByRow[row][cyr-1] * Number(eval(hoursName).value); // replace with table values
}

if(isNaN(labor000))
{
eval(costName).value = '---'
eval(fteName).value = '---'
}
else
{
eval(costName).value = labor000.toFixed(0)
eval(fteName).value = (Number(eval(hoursName).value) / jsProdHrsTot[cyr-1]).toFixed(4) }
}
**************************************************
**************************************************


Rather than calculate the dollar values for CY1 and CY2 as is done above, I want to use the values from the database table, TABLE_SUB. I have tried numerous things, but I'm clearly not a Javascript expert as what appears simple to some id giving me a lot of grief. If more information is needed to help understand the process I'm trying to achieve, I will be more than happy to provide what I can.

Thanks for you help - any and all will be appreciated.

Bill

Bill
lohneb@bellsouth.net

 
Sorry... too much code not pasted between [code][/code] tags for me to be able to understand what your code is trying to achieve.

I think you are of the opinion you can access ColdFusion variables (which are considered server-side) using Javascript (client-side). This is not the case.

You would have to output the individual values to a javascript array (maybe) and then access them that way. Maybe you would output the values to the individual for elements (using CF) in the first instance.

See if that makes any sense, and if not... assume that we all need some more input from you [smile]

Cheers,
Jeff
 
OK Jeff - let me look at your suggestions. I will get back with more information.



Bill
lohneb@bellsouth.net

 
Jeff,

Finally back to working on this problem. I will try to make the assignments directly in the 'for' elements using the CF query. If I can make that work - great - otherwise I will be back with more information. Seems like it should be quite simple, but it's giving me lots of grief.

Thanks,

Bill
lohneb@bellsouth.net

 
Hi all -

The following piece of code:


******* start of copy **********
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<script language="JavaScript">
<cfquery name="blx" datasource="MIDAS">
SELECT st_hr,
stlabor_l,
plc_cd
FROM FORECAST_SUB
WHERE prjid = '43'
AND rev = 0
AND ver = 'C'
AND contract_id = 1
AND cnt_yr = 3
AND plc_cd = '999999'
AND st_hr > 0
AND baseline = 'N'
</cfquery>
<cfset idx = blx.recordcount>
alert("idx value is <cfoutput>#idx#</cfoutput>")

for (cnt = 1; cnt <= <cfoutput>#idx#</cfoutput>; cnt++)
{
document.write("The value of the count variable is " + cnt + "<br>")
document.write("The value of labor is " + <cfoutput>#blx.stlabor_l#[cnt]</cfoutput> + "<br>")
}
</script>

<html>
<head>
<title>Javascript</title>
</head>

<body>

</body>
</html>
******* end of copy **********


yields the following result:


******* start of copy **********
The value of the count variable is 1
The value of labor is undefined
The value of the count variable is 2
The value of labor is undefined



--------------------------------------------------------------------------------
Queries

blx (Records=2, Time=0ms)
SQL =
SELECT st_hr,
stlabor_l,
plc_cd
FROM FORECAST_SUB
WHERE prjid = '43'
AND rev = 0
AND ver = 'C'
AND contract_id = 1
AND cnt_yr = 3
AND plc_cd = '999999'
AND st_hr > 0
AND baseline = 'N'
******* end of copy **********

which is not correct. The result that I'm looking for is:


******* start of copy **********
The value of the count variable is 1
The value of labor is 245516
The value of the count variable is 2
The value of labor is 281232





--------------------------------------------------------------------------------
Queries

blx (Records=2, Time=0ms)
SQL =
SELECT st_hr,
stlabor_l,
plc_cd
FROM FORECAST_SUB
WHERE prjid = '43'
AND rev = 0
AND ver = 'C'
AND contract_id = 1
AND cnt_yr = 3
AND plc_cd = '999999'
AND st_hr > 0
AND baseline = 'N'
******* end of copy **********


The #blx.stlabor_l#[cnt] code is not being indexed with values of 1 and 2 as wanted. I know this is probably simple, but I'm not getting there! Any help is of course appreciated.



Bill
lohneb@bellsouth.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top