Solved

Submitting value per table row problem

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

13 Experts available now in Live!

Get 1:1 Help Now