Hidden Input Ordering in FireFox Form Submission

Posted May 3, 2006 at 1:17 PM

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:

 Launch code in new window » Download code as text file »

  • 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.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

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

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


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 21, 2009 at 6:47 PM
Hal Helms - Real World Object Oriented Development, Sarasota - Day Five
@charlie griefer, Thank you.. ... read »
Nov 21, 2009 at 5:15 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jose Galdamez, Oh heh yeah I didn't paste the whole code. I should have defined the vars -- my bad. It's fixed thou. Thanks. ... read »
Nov 21, 2009 at 4:49 PM
Styling The ColdFusion 8 WriteToBrowser CFImage Output
Great work yet again Ben! Whilst I didn't use this whole code, I copied some of your regex code for a similar problem with the lack of an alt attribute and unescaped ampersands in CFIMAGE for Railo 3 ... read »
Nov 21, 2009 at 1:13 PM
My First ColdFusion Builder Extension - Encrypting And Decrypting CFM / CFC Files
@Ben, Because I am pedantic, I just want to make sure that everyone knows there is absolutely no encryption going on. There is only encoding and obfuscation. The cfencode tool only obfuscates your C ... read »
Nov 21, 2009 at 12:28 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jody I can't seem to get your code sample to work. If you are still having problems, try this code out and see if it gets you what you wanted. <!--- Comma delimited list with various duplicates ... read »
Nov 21, 2009 at 11:03 AM
Groovy Operator Overloading Does Not Work In The ColdFusion Context
Hi Ben, Thanks for this informative post. Now I am reading ur old posts too ... read »
Nov 21, 2009 at 10:56 AM
HostMySite.com Has The Best ColdFusion Hosting
@Mehul, Yes very nice people, however several downtimes per day which was not acceptable. Hence we had to move out. I am glad you are having good luck with them so far. ... read »