Hidden Input Ordering in FireFox Form Submission

Posted May 3, 2006 at 1:17 PM by Ben Nadel

Tags: Javascript / DHTML

I just has a wicked time trying to debug a crazy issue a co-worker was having. He was changing the sort of table rows within a table. Each row had a hidden input (for ID) in the first TD. Each row input had the same name, so that when the form was submitted, each ID would be submitted into a comma delimited list. We assumed that the order of the IDs in the list would mirror the order of the TRs (and hence the child input) in the submitted page.

This works in Internet Explorer (IE) but not in FireFox (FF). In FF, the list of the IDs did not match the physical order of the inputs in the submitted page and it didn't seem to follow any sort of logical order. It was driving me crazy, trying to help him, and then a solution popped into my head: Don't rely on the hidden inputs. Maintain a list of IDs outside of the table.

To do so, after each table row sort, you had to loop over each row, find the input, grab its ID and append that to a hidden value list of IDs. This worked perfectly. The only overhead is that you need to maintain the list after each sort, but that is fairly small in the grand scheme of things (if you are married to the idea of sorting table rows).

This is some example code of the UpdateValueList() function that takes, as an argument, the last row that was sorted:

  • function UpdateValueList( objRow ){
  • var objForm = document.forms[0];
  • var objValueList = objForm.elements["lst_id"];
  • var objTBody = objRow.parentNode;
  • var intI = null;
  • var objInput = null;
  •  
  • // Reset value list.
  • objValueList.value = "";
  •  
  • // Loop over TRs (by looping over TBodys child nodes).
  • for (intI = 0 ; intI < objTBody.childNodes.length ; intI++){
  •  
  • // Get the current row of the TBody.
  • objRow = objTBody.childNodes[ intI ];
  •  
  • // Check to make sure we have TR (not a text node);
  • if (objRow.nodeType == 1){
  • // Get the first input for the Row. Search for all INPUT elements within THIS TR.
  • objInput = objRow.getElementsByTagName("input")[0];
  •  
  • // Add that value back to the value list.
  • objValueList.value += ( objInput.value + ", " );
  • }
  • }
  •  
  • }

As you can see, I loop through the childNodes of the Table Body to get each Table Row, then based on the Table Row, I query for the input tags (the first of which is the hidden input ID). Then, the value list hidden field (which will be used for form submission) is updated.



Reader Comments

May 10, 2006 at 6:50 PM // reply »
1 Comments

Good Luck! http://www.google.com


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
May 20, 2013 at 4:24 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I thought when you used array notation to reference queries you always had to have the row or it would throw a similar error as well? ... read »
May 20, 2013 at 11:45 AM
Using jQuery's Animate() Step Callback Function To Create Custom Animations
This is really useful. I found out that you don't actually have to use a dummy css property (surprisingly). To animate a property in a linear-gradient for instance I did this this.css('someLinearGra ... read »
May 20, 2013 at 10:51 AM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Josh, Oh snap! You're totally right! I'm not sure I've ever tried that. I did know that you can call a number of other array-methods on ColdFusion query columns: http://www.bennadel.com/blog/167 ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools