Solved

Submitting value per table row problem

Posted on 2007-04-05
5
196 Views
Last Modified: 2008-01-09
I want to be able to make changes per table row on a form.  I have multiple companies and each can be deactivated or ranked, but when I click on submit it submits all rows in the form. Can I submit the value of an individual row. Here is my code.
<form name="rank" action="index.cfm?mode=rankem">
<tr>
<td><img src="images/checkmark.jpg" alt="Check"></td>
<td><a href="index.cfm?mode=company&claimtype=editcompany&co_id=#co_id#">#companyname#</a></td>
<td>#post_date#</td>
<td><input type="checkbox" name="deactivate" <cfif acctdisabled eq 1>checked</cfif>></td>
<td>
      <select name="ranking">
            <option value="#ranking#" selected="selected">#ranking#</option>
            <cfloop index="myrank" from="1" to="100">
                  <option value="#myrank#">#myrank#</option>
            </cfloop>
      </select>
</td>
<td align="center">
      <input type="image" src="images/submitblue.gif">
</td>
</tr>
</form>
0
Comment
Question by:dudeatwork
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 18859157

Here's an example I have for "users" , just substitute for your companies...



Append a "record number" to the end of each field name, this
number will associate together fields of the same record.  
Also create a hidden field to hold the total number of records
(this isn't required but is helpful).


<cfoutput query="getUsers">
   <cfset variables.ct = getProducts.currentRow>
 <tr>
   <td>First Name:</td><td><input type="text"   name="firstName#variables.ct#" value="#form.firstName#"></td>
 </tr>
 <tr>
   <td>Last Name:</td><td><input type="text" name="lastName#variables.ct#" value="#form.lastName#"></td>
 </tr>
 <tr>
   <td>Login Name:</td><td><input type="text"   name="username#variables.ct#" value="#form.username#"></td>
 </tr>
</cfoutput>
<cfoutput>
<input type="hidden" name="userID#variables.ct#" value="#userID#">
<input type="hidden" name="totalRecords" value="#variables.ct#">
</cfoutput>



Processing Page
---------------
When you process it, you loop through the number of records from 1 to X
and convert them back to regular variables and update them (you don't really need to convert
them back to variables without numbers, they're just easier to work with).


<cfloop index="ii" from="1" to="#form.totalRecords#">
  <cfset variables.firstName = form['firstName' & kk]>
  <cfset variables.lastName  = form['lastName' & kk]>
  <cfset variables.username  = form['username' & kk]>
  <cfset variables.userID    = form['userID' & kk]>
 
  <cfquery name="UpdateUser" datasource="DSN">
    update user
        set firstName = '#variables.firstName#'
          , lastName  = '#variables.lastName#'
            , userName  = '#variables.username#'
       where userID = #val(variables.UserID)#
  </cfquery>
</cfloop>
 
0
 

Author Comment

by:dudeatwork
ID: 18860205
Is this what I can use? From that code I submitted, if you have 4 companies outputed to a table, each row...
company       date            Disabled(y/n)         Ranking(1-100)        Submit
**************************************************************************************
Company1    1/1/01              No                              100                 <submit button>
Company2    1/1/01              Yes                            80                  <submit button>
Comapny3    1/2/06              No                              60                  <submit button>
Company4     10/2/07           No                              40                   <submit button>

Diabled is a checkbox, ranking is a selectbox and each row has a submit button. I dot want to update all companies just that one row.Is the code you sent do just that? Thanks again. In esssence you could update all companies with your code right?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 18860269

 Oh, my code would have only one Submit button any yes, all companies on the page would be updated at once.  

 Which would you prefer?  
 Update all companies at once or  allow only one company to change.

-   Typically, I would update all, I am afraid of it being confusing for someone to make a change on line 1 and also on line 2 and when he clicks Submit only one change takes effect.  

 
0
 

Author Comment

by:dudeatwork
ID: 18860804
I would prefer one at a time and not all of them.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 18860922

 You can do one of two things.  You can associated the counter to your submit button, so that if they click Submit5, you know to process record 5.

 Alternatively, you can create a separate form for each row.  In each form, you would not need the counter because each form would submit on its own and not include any of the other values.

 
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now