File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Hidden input elemnets via POST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hidden input elemnets via POST" Watch "Hidden input elemnets via POST" New topic
Author

Hidden input elemnets via POST

Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

I am facing an issue when I am trying to submit a JSP page .


I will describe in short the scenario so that it would be clear.

The Scenario

I have some input elements made up in a html component:



on JSP page.

The table has many <tr>. These <tr> have been given ids, for e.g. .

Now I am trying to pass a comma separated list of these tr ids to server side code or Servlet.

The comma separated list is formed with looping some logic on submit of JSP or more specifically a form.

The Problem:

When I submit the form sometimes I do not receive the comma separated values mentioned above at server side code.

This happens occasionally. Now when I put some delay through Java Script like setTimeOut() I do not face the issue.

So can anyone please help me guiding on this?

Is Java Script behavior a bit non - sequential sometimes?

Thanks in advance.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Sounds like this is more of a JavaScript question than a JSP question.

And no, JavaScript behavior is not "a bit non - sequential sometimes".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

Yes Bear Bibeault it is a Java Script issue.

But I thought someone could help me out here.

One more doubt I had : My form submission is based on a "onclick" event. So is it possible that JavaScript executions is not finished fully but form is submitted?

Why I am asking is this because I get the comma separated list empty at server side. And most importantly there is no Java Script error too.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Moved to the HTML forum.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
What JavaScript code is executing? Also ids can not be numbers.

Eric
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

Eric Pascarello,

The JavaScript executing:



The loop above which you see is not completed till the form gets submitted.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If data is an array, there is no need to loop, plus your way gives you a trailing comma at the end.



Looking at the code you posted, it should not have any timing issues.

Only way I would see a timing issue is if the button was a type="submit" or if it was a <button>.

Eric
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

Eric Pascarello,

Only way I would see a timing issue is if the button was a type="submit" or if it was a <button>.


So in any case is it possible that the Java Script code did not completed fully but the form got submitted?

What I mean is whether Java Script would behave asynchronously?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Of course, JavaScript has asynchronous aspects: events, timers, Ajax, etc.

But, if you mean "will statements execute out of order", then no.
Sumukh Deshpande
Ranch Hand

Joined: Feb 17, 2008
Posts: 87

Thanks a lot for all your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hidden input elemnets via POST
 
Similar Threads
Unable to connect to database
Problem Uploading Files
Struts 2 checkboxlist error - list key could not be resolved
problem to call errorpage in jsp
How to send Parameters from JSP to a Servlet?