Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
DJ5MD #1
Insert Loop values into DB Problem
:confused;
How do I call the loop when inserting the values into my DB? I am getting an
error message.
Here is the Insert Statement:
Insert into Scenario
(ScenarioID, Scenario_Desc, Scenario, TeamOwner, TeamOwnerSub,
ProcessOwner, ScriptOwner, Status)
Values
('#Session.ScenarioID#',
'#Trim(Form.Scenario_Desc)#',
'#Trim(Form.Scenario)#',
'#trim(form['myTeam' & myLoop])#',
'#trim(form['mysubTeam' & myLoop])#',
'#Trim(Form.Process)#',
'#Trim(Form.Script)#',
'#Trim(Form.Status)#',)
Error Message:
Variable MYLOOP is undefined.
The error occurred in
D:\Inetpub\wwwroot\Projects\TestScenario\_actions\ act_CreateScenario.cfm: line
10
8 : '#Trim(Form.Scenario_Desc)#',
9 : '#Trim(Form.Scenario)#',
10 : '#trim(form['myTeam' & myLoop])#',
11 : '#trim(form['mysubTeam' & myLoop])#',
12 : '#Trim(Form.Process)#',
DJ5MD Guest
-
#39464 [NEW]: Range function produces odd values in foreach loop
From: netnessie at gmail dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: *Programming Data Structures Bug... -
What's faster - loop for insert or insert...select.
What is faster if I'm moving large numbers of records (anywhere from 10,000 to 300,000 records per archive) from one query to another table? 1)... -
Can you put an Insert Command object in a loop?
Hi I am trying to figure out how to insert a variable number of records into one table in Access, therefore without stored procedures, in ASP... -
insert record loop
Can anyone help me to create an insert record loop using asp vbs? -
How to select and then loop while insert
I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and... -
BSterner #2
Re: Insert Loop values into DB Problem
What is 'myLoop' supposed to represent? The index of the loop? What does the entire code for the loop look like?
BSterner Guest
-
DJ5MD #3
Re: Insert Loop values into DB Problem
Here is the JS code:
<script language="javascript">
var aryTeams = new Array();
<cfset variables.JSLoop = 0 />
<cfoutput>
<cfloop query="qrygetteams">
aryTeams[#variables.JSLoop#] = new
Array("#qrygetteams.IssueTeamTitle#", "#qrygetteams.IssueSubTeamTitle#");
<cfset variables.JSLoop = variables.JSLoop + 1 />
</cfloop>
</cfoutput>
<!--- Function that will update the Selects --->
function tsrUpdSelects(frstSel, scndSel, thisSel) {
var z;
var chkTeam = "";
if(thisSel.name == frstSel.name) {
scndSel.options.length = 0;
scndSel.options[scndSel.length] = new Option("Select SubTeam",
"");
if(thisSel.options[thisSel.selectedIndex].value != "") {
for (z = 0; z < aryTeams.length; z++) {
if(aryTeams[z][0] ==
thisSel.options[thisSel.selectedIndex].value &&
chkTeam.lastIndexOf(aryTeams[z][1] == -1)) {
scndSel.options[scndSel.length] = new Option
(aryTeams[z][1], aryTeams[z][1]);
chkTeam = chkTeam + aryTeams[z][1];
}
}
}
}
}
</script>
Here is the Select Box code:
<cfloop from="1" to="1" index="Variables.myLoop">
<tr>
<td height="30">Team Ownership: </td>
<cfset TeamList = ""/>
<td><select name="myTeam#myLoop#"
onChange="tsrUpdSelects(this,this.form.mySubTeam#M yLoop#, this);">
<option value="" selected> Select Project Team</option>
<cfloop query="qrygetteams">
<cfif not listFindNoCase(TeamList, qrygetteams.IssueTeamTitle,",")>
<option
value="#qrygetteams.IssueTeamTitle#">#qrygetteams. IssueTeamTitle#</option>
<cfset TeamList = listAppend(TeamList,qrygetteams.IssueTeamTitle,"," ) />
</cfif>
</cfloop>
</select>
<img src="../../_images/spacer.gif" width="25" height="10">
<select name="mySubTeam#myLoop#"
onChange="tsrUpdSelects(CreateScenario.myTeam#myLo op#, this);">
<option value="" selected> Select Project SubTeam</option>
</select>
</td>
</tr>
</cfloop>
</cfoutput>
DJ5MD Guest
-
BSterner #4
Re: Insert Loop values into DB Problem
Variables in the "variables" scope don't persist across page requests. The
page you're posting to, that's trying to access...
'#trim(form['myTeam' & myLoop])#',
'#trim(form['mysubTeam' & myLoop])#',
Knows about the 'form' variables', but not the 'myLoop' variable that was set
in the previous page. This is the case even if the page is posting to itself.
Couple questions.
1) Why do you have a loop that loops from '1' to '1'?
2) Consider using the 'selectedIndex' property of your select boxes to set
values, rather than looping through all that stuff.
(Assuing you have a form with <form name="myForm"....>
function updateSubTeam() {
var theForm = document.myForm;
var myTeam1Index = theForm.myTeam1.options.selectedIndex;
var selectVal = aryTeams[myTeam1Index-1][1];
theForm.mySubTeam1.options[0] = new Option("Select SubTeam", "");
theForm.mySubTeam1.options[1] = new Option (selectVal, selectVal);
}
BSterner Guest
-
DJ5MD #5
Re: Insert Loop values into DB Problem
I was modifying a JS script and CF that allowed for Multiple Related Select
boxes. I had no idea how to do that, so I found this code and modified to my
needs so I have no idea why the cfloop is 1 to 1. I do know that when I
change the cfloop to 1 to 5 then the form elements show up 5 times on the page
(repeat).
If I use this code then will I still be able to have the Multiple related
select boxes?
DJ5MD Guest
-
BSterner #6
Re: Insert Loop values into DB Problem
Ok, well get rid of the <cfloop> tags then. The purpose of a loop is to
um...."loop", and it sounds like you don't need that. Just hard-code the '1'
and the '2' in your select box names.
"If I use this code then will I still be able to have the Multiple related
select boxes?"
Yes, it should. Wouldn't hurt to test it in multiple browsers, though. Just
make sure all the element names match up.
BSterner Guest
-
DJ5MD #7
Re: Insert Loop values into DB Problem
:)
So where it says myTeam#myLoop# for MyTeam I would use myTeam[1] and when
referencing mySubTeam#myLoop# I would use mysubTeam[2]?
Also, what code am I replacing with the code you suggested and where do I
place it?
DJ5MD Guest
-
BSterner #8
Re: Insert Loop values into DB Problem
Names would be "myTeam1" & "mySubTeam1".
BSterner Guest



Reply With Quote

