Hi,
I have a fuse that returns part-related data from a database. It looks like
this:
<cfswitch expression = "#Attributes.Fuseaction#">
<cfcase value = "getpartsreport">
<cfinclude template = "logic/act_setqueryvars.cfm">
<cfinclude template = "query/qry_getparts.cfm">
<cfinclude template = "query/qry_getecns.cfm">
<cfinclude template = "query/qry_getecrs.cfm">
<cfinclude template = "query/qry_getdevs.cfm">
<cfinclude template = "logic/act_setdspvars.cfm">
<cfinclude template = "display/js_formcontrol.cfm">
<cfinclude template = "display/dsp_searchbypn.cfm">
</cfcase>
</cfswitch>
The fuse takes user input from a form, preps the part number or range of part
number variables for query, queries the database, preps the results for form
display, then displays them. If the user wants data on a range of parts, all
the parts returned will appear in a select box. A Javascript function will
detect changes in the box's selectedindex, then update some associated display
elements whose values are included in data objects under a matching index.
In the act_setdspvars.cfm template, I've wrapped a <cfloop query> tag around a
javascript tag like this:
<cfloop query="getparts">
<cfset part = getparts.part>
<cfset description = getparts.description>
<cfset revision = getparts.revision>
<cfset change_date = getparts.change_date>
<cfset filename = getparts.filename>
<cfset size_printed = getparts.size_printed>
<cfset thisrow = getparts.currentrow - 1>
<cfoutput>
<script language="Javascript">
var pn_#thisrow# = new Object();
pn_#thisrow#.part = #part#;
pn_#thisrow#.description = #description#;
pn_#thisrow#.revision = #revision#;
pn_#thisrow#.change_date = #change_date#;
pn_#thisrow#.filename = #filename#;
pn_#thisrow#.size_printed = #size_printed#;
</script>
</cfoutput>
</cfloop>
I keep getting a javascript error error with this code. It says Error: line
(x). Expected ;.
I'm not missing any semicolons. At this point, I haven't hooked in the
onchange event for the select box. The browser (IE6) just seems to throw an
error as soon as it sees this script.
Help!
Dan Bracuk - 29 Dec 2005 22:22 GMT
Change this:
<cfoutput>
<script language="Javascript">
var pn_#thisrow# = new Object();
pn_#thisrow#.part = #part#;
pn_#thisrow#.description = #description#;
pn_#thisrow#.revision = #revision#;
pn_#thisrow#.change_date = #change_date#;
pn_#thisrow#.filename = #filename#;
pn_#thisrow#.size_printed = #size_printed#;
</script>
</cfoutput>
to this
<cfoutput>
<script language="Javascript">
var x = 1;
/*
var pn_#thisrow# = new Object();
pn_#thisrow#.part = #part#;
pn_#thisrow#.description = #description#;
pn_#thisrow#.revision = #revision#;
pn_#thisrow#.change_date = #change_date#;
pn_#thisrow#.filename = #filename#;
pn_#thisrow#.size_printed = #size_printed#;
*/
</script>
</cfoutput>
Then move the start of the comment down one line at a time until you get your
error.
ixnay5 - 29 Dec 2005 23:36 GMT
Thanks for the response, Dan,
Essentially, I've done that and I still don't understand why I'm getting the
error. I changed the variable names a little to avoid a potential name
conflict with one of the display elements. Here's where I get the error now:
<cfloop query="getparts">
<cfset thispart = getparts.part>
<cfset thisdesc = getparts.description>
<cfset thisrev = getparts.revision>
<cfset thischange_date = getparts.change_date>
<cfset thisfilename = getparts.filename>
<cfset thissize_printed = getparts.size_printed>
<cfset thisrow = getparts.currentrow - 1>
<cfoutput>
<script language="Javascript">
var x = 1;
var pn_#thisrow# = new Object();
pn_#thisrow#.thispart = #thispart#;
pn_#thisrow#.thisdesc = #thisdesc#;
/*
pn_#thisrow#.thisrevision = #thisrev#;
pn_#thisrow#.thischange_date = #thischange_date#;
pn_#thisrow#.thisfilename = #thisfilename#;
pn_#thisrow#.thissize_printed = #thissize_printed#;
*/
</script>
</cfoutput>
</cfloop>
It never fails to error on thisdesc. Beats the heck out of me!
e
Dan Bracuk - 30 Dec 2005 03:39 GMT
Originally posted by: ixnay5
Thanks for the response, Dan,
Essentially, I've done that and I still don't understand why I'm getting the
error. I changed the variable names a little to avoid a potential name
conflict with one of the display elements. Here's where I get the error now:
<cfloop query="getparts">
<cfset thispart = getparts.part>
<cfset thisdesc = getparts.description>
<cfset thisrev = getparts.revision>
<cfset thischange_date = getparts.change_date>
<cfset thisfilename = getparts.filename>
<cfset thissize_printed = getparts.size_printed>
<cfset thisrow = getparts.currentrow - 1>
<cfoutput>
<script language="Javascript">
var x = 1;
var pn_#thisrow# = new Object();
pn_#thisrow#.thispart = #thispart#;
pn_#thisrow#.thisdesc = #thisdesc#;
/*
pn_#thisrow#.thisrevision = #thisrev#;
pn_#thisrow#.thischange_date = #thischange_date#;
pn_#thisrow#.thisfilename = #thisfilename#;
pn_#thisrow#.thissize_printed = #thissize_printed#;
*/
</script>
</cfoutput>
</cfloop>
It never fails to error on thisdesc. Beats the heck out of me!
e
So I guess the next step would be to do this right before the script
<cfdump var="#thisdesc#"> and look for clues. Perhaps one of those nefarious
apostrophes.
Then, inside your javascript, try to window.alert that variable and see what
happens.
Ali Soylu - 29 Dec 2005 23:47 GMT
You should use quotes when assigning strings to javascript variables like:
pn_#thisrow#.description = "#description#";
ALi
ixnay5 - 30 Dec 2005 22:21 GMT
I'd definitely tried that a number of times and still had problems, but today I
went for it again, and it's all working. I've modified the javascript a little
more, and this is the approach I'm using now:
<script language="Javascript">
var part = new Array();
</script>
<cfloop query="getparts">
<cfset thispart = getparts.part>
<cfset thisdesc = getparts.description>
<cfset thisrev = getparts.revision>
<cfset thischange_date = getparts.change_date>
<cfset thisfilename = getparts.filename>
<cfset thissize_printed = getparts.size_printed>
<cfset thisrow = getparts.currentrow>
<cfoutput>
<script language="Javascript">
part[#thisrow#] = new Object();
part[#thisrow#].thispart = "#thispart#";
part[#thisrow#].thisdesc = "#thisdesc#";
part[#thisrow#].thisrevision = "#thisrev#";
part[#thisrow#].thischange_date = "#thischange_date#";
part[#thisrow#].thisfilename = "#thisfilename#";
part[#thisrow#].thissize_printed = "#thissize_printed#";
</script>
</cfoutput>
</cfloop>
and then for the client side:
function getIndex()
{
var box = pnsearch.pn;
var number = box.options[box.selectedIndex].value;
pnsearch.description.value = part[number].thisdesc;
pnsearch.rev.value = part[number].thisrevision;
pnsearch.update.value = part[number].thischange_date;
pnsearch.filename.value = part[number].thisfilename;
pnsearch.size.value = part[number].thissize_printed;
}
Thanks everyone for your help. Also, I WILL come back and answer somebody
else's questions! :beer;