order of retreiving form parameters using javascript
Stu Johns
Ranch Hand
Joined: Aug 11, 2008
Posts: 63
posted
0
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
Joined: Oct 08, 2006
Posts: 2458
posted
0
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.
This guy is so lazy!!!<br />There is nothing left!
Stu Johns
Ranch Hand
Joined: Aug 11, 2008
Posts: 63
posted
0
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
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
There is no way to guarantee it.
Eric
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: order of retreiving form parameters using javascript