?
Solved

Submitting value per table row problem

Posted on 2007-04-05
5
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 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