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]; } } } } } Here is the Select Box code: Team Ownership: [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => DJ5MD [ip] => djacobson@jhmi. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 3 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Insert Loop values into DB Problem - Coldfusion - Advanced Techniques

Insert Loop values into DB Problem - Coldfusion - Advanced Techniques

: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)#',...

  1. #1

    Default 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

  2. #2

    Default 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

  3. #3

    Default 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

  4. #4

    Default 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 = doent.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

  5. #5

    Default 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

  6. #6

    Default 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

  7. #7

    Default 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

  8. #8

    Default Re: Insert Loop values into DB Problem

    Names would be "myTeam1" & "mySubTeam1".
    BSterner Guest

Similar Threads

  1. Question Insert from ASP to SQL using recordset data as values in insert statement
    By JasonM in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 13th, 05:54 PM
  2. What's faster - loop for insert or insert...select.
    By mr. modus in forum Coldfusion Database Access
    Replies: 2
    Last Post: December 10th, 01:57 AM
  3. Can you put an Insert Command object in a loop?
    By Tim Pollard in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 12th, 09:47 PM
  4. insert record loop
    By ericMorcombe in forum Dreamweaver AppDev
    Replies: 0
    Last Post: February 24th, 05:13 PM
  5. How to select and then loop while insert
    By Mansoor Aleem in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: July 8th, 08:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •