Skip to main content
Participating Frequently
April 29, 2008
Question

Adding an extra column

  • April 29, 2008
  • 5 replies
  • 704 views
My query will produce three records, so I output/display them in a table :

<cfoutput query="qry">
<tr>
<td>#line_item#</td><td>#part_number#</td><td>#requestor#</td>
</tr>
</cfoutput>

What I need to do is add an extra column to the end of each record, to enter comments :
<td><input type="text" name="comments" size="50" maxlength="50"></td> so the new row will look like :

<td>#line_item#</td><td>#part_number#</td><td>#requestor#</td><td><input type="text" name="comments" size="50" maxlength="50"></td>

When the user enters the comments and submits the form, I want to insert the line_item, part_number, requestor, and comments into another table.

My question is how do I associate each comments text with the existing corresponding record ?
    This topic has been closed for replies.

    5 replies

    Participating Frequently
    May 12, 2008
    I need help with this again, almost works but not quite.

    Here is the code I have for my form :

    <cfoutput query="qry">
    <tr>
    <td align="center"><cfinput type="checkbox" name="del/#ref_number#/#ref_line_item#" value="Yes"></td>
    <td align="center">#ref_line_item#</td>
    <td align="center">#ref_action#</td>
    <td align="center">#quantity#</td>
    <cfif qry.ref_action is "Receive">
    <td>PO: #qry.po_number#,
    Item: #qry.item#, P/N: #qry.part_number#</td>
    <cfelseif qry.ref_action is "RTV">
    <td>Shipping Document Number: #qry.tracking_number#</td>
    <cfelseif qry.ref_action is "Other">
    <td>Instructions: #qry.instructions#</td>
    </cfif>
    <td align="center"><cfinput type="text" name="comments/#ref_number#/#ref_line_item#" size="50" maxlength="50"></td>
    </tr>
    </cfoutput>


    I am,attepting to associate the commets field with the checkbox field.

    Here is my action page :

    <cfif isDefined("form.fieldnames") and mid(form.fieldnames,1,4) is "Del/">
    <cfloop index="i" list="#form.fieldnames#" delimiters=",">


    <cfif left(i,4) is "del/">

    <cfset select_ref_number = listgetat(i, 2, "/")>
    <cfset select_ref_line_item = listlast(i, "/")>

    <cfset commentsName = "comments/#select_ref_number#/#select_ref_line_item#">
    <cfset select_comments = form[commentsName]>

    <cfif select_comments is "">
    <cflocation url="form.cfm?showAlert&ref_number=#select_ref_number#&line_item=#select_ref_line_item#">
    </cfif>

    update query goes here
    </cfif>
    </cfloop>


    <cfoutput>
    <cflocation url="next_form.cfm?ref_number=#form.ref_number#">
    </cfoutput>
    <cfelse>
    <cfoutput>
    Error Message goes here
    </cfoutput>
    </cfif>

    If none of the checkboxes are selected and the form submitted, I need to display an error message. If any of the chekcboxes are selected but the comments are blank, then I need to display anohter error message.The form should only submit if at least one of the checkboxes are checked and there are commets.

    It seems to work halfway. If the errors are detected, and corrected, the errors continue to come up. If it is done right the first time (checkbox and commerts), it seems to work fine.

    But overall, I think it is not working.

    Can someone please help and tell me what I am doing wrong ?

    Thanks
    Inspiring
    May 2, 2008
    What happens when you output the ThisRecord variable.
    Inspiring
    May 1, 2008
    Give all the checkboxes the same name and different values. For the comments, read the thread again, the answer is the same.
    Participating Frequently
    May 2, 2008
    I cant seem to get this to work.

    <cfloop list="#form.fieldnames#" index = "ThisItem">
    <cfif left(ThisItem, 9) is "comments_">
    <cfset ThisRecord = Mid(ThisItem, 10, len(ThisItem - 9))>
    <cfset ThisValue = form[ThisItem]>

    ThisValue is the content of the comments_6, which corresonds to line item 6 ? I did a cfoutput and it show Yes.
    I just need to get the each comments entry to correspond to the approriate line iteme records.
    Inspiring
    April 30, 2008
    I'll be doing something like that later today. My method goes something like this.

    <cfloop list="#form.fieldnames#" index = "ThisItem">
    <cfif left(ThisItem, 9) is "comments_">
    <cfset ThisRecord = Mid(ThisItem, 10, len(ThisItem - 9))>
    <cfset ThisValue = form[ThisItem]>
    code to do somehing with those variables
    closing tags.
    Participating Frequently
    May 1, 2008
    I think I understand what you are doing here.

    However, here is my original post and methods, how would I incorporate your method into this one ?

    I use the following code to display display all line items from a query, and put in checkboxes for each line item, so that if the box is checked, that line item will be deleted :

    <cfoutput query="qry">
    <tr>
    <td align="center"><input type="checkbox" name="del_#urdn_number#_#urdn_line_item#" value="Yes"></td>
    <td align="center">#qry.line_item#</td>
    <td align="center">#qry.action#</td>
    <td align="center">#qry.quantity#</td>

    the action page :

    <cfloop index="i" list="#form.fieldnames#" delimiters=",">

    <cfif left(i,4) is "del/">
    <cfset select_urdn_number = listgetat(i, 2, "/")>
    <cfset select_urdn_line_item = listlast(i, "/")>

    What I need to do now is add a input text field, to each line item displayed, for the user to enter comments explaining why they watn to delete that line item. I then need to insert this comment that corresonds to each line item into a table.

    Since this comments input text is not part of the query, how do I associate it with each line item ?
    Inspiring
    April 29, 2008
    Use the name attribute of your cfinput tag. instead of simply comments, call it comments#something_from_your_query#
    Participating Frequently
    April 29, 2008
    I changed the name from coments to comments-#line_item# and when I display it, it is comments_6, which correponnds to the line_item (6) that is retrieved and displayed.

    Now how/what do I do to insert the value of the comments into the table so that it corresponds to the line item,in this case, 6 ?