Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

order of retreiving form parameters using javascript

 
Stu Johns
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if its possible to loop through the parameters in a html form in the order that they appear on the screen?

thanks

Stu
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be sure, aren't you confusing Javascript with JSP (JavaServer Pages)? You normally don't use Javascript to process request parameters. I also don't see how that's possible when you're using POST instead of GET. On the other hand, when using Javascript for this, I would just walk through the DOM tree. Much easier.

At any way, the order of the request parameters is not specified in the HTML specification. It may be dependent on the webbrowser and appserver used. I wouldn't rely on this.

Look for a solution in another direction. What is it that you're trying to process? Tabular data or so? Try using input name suffixes the smart way. Pass a hidden input element in each row denoting the row ID and suffix the name of all other input elements in the same row with that value.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you should tell us what you're really trying to accomplish?
 
stef li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i 'm not clear what you really want to do!
 
Stu Johns
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have form with a bunch of parameters in it,
in this case a start date and an end date,
I have tested the code and it is not guaranteed that the order of the elements will be displayed, I didnt know if there was a way to ensure the order the parameters would be retreived in the loop, (ie the order they are in the html source).
Thanks for your replies, (I am not lazy though!), I could uniquely identify them as suggested above if order cant be guaranteed another way.
Thanks again for your suggestions

Stu.

>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to guarantee it.

Eric
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're traversing the HTML DOM tree, then they will guaranteed be in the same order as they appear in the HTML output. That's why I suggested to crawl the HTML DOM.

It was really confusing that you mentioned "parameters" instead of "input values" or something more client-side specific.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic