Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Submitting value per table row problem

Posted on 2007-04-05
5
Medium Priority
?
203 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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