Solved

Submitting value per table row problem

Posted on 2007-04-05
5
198 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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