• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submit Methods pulling same data

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an HTML page that displays 5 buttons using the form tag. Each of these buttons start a different servlet that returns some database information to me. I would like the user to be able to put in a date range so I have added 2 text field. One for FromDate and the other for ToDate.
What I need to know is how to pull data from those fields for all the buttons. I don't want to have to have text fields for each button.
Here is my HTML code.
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to add 2 hidden fields to each form and populate those before the form submission. Something like onsubmit="populateHidden(startDate,endDate);"
You could do similar trickery with a querystring, using HTTP GET rather than post.
Hope that helps!
[ May 10, 2002: Message edited by: Brian Glodde ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand what you are saying, but could you show me? I mean, where do I put the onsubmit=" "
and what is the format for the hidden fields?
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg, Here's one done for you. I will warn you, I did this quickly in IE, the syntax is definitely wrong for NS. You'll have to branch it to document.layers for that.

* the eval statement causes an error with UBB, so I am using "e v a l".
For the subsequent forms, you'll just change the arguments to match. The next form would be
onsubmit="return setDates(1, 'ATickets');"
Happy coding!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian, you are the man!! Thanks a mill.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I tried the above code and here is what happens.
I get this error
'document.forms.0.HDStats_startDate' is null or not an object
And I am entering data into the textFields.
Here is my HTML

Thanks
 
swaroop shastri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I modified your code a bit. Check to c if this works. I did not try it out but my experience says that it might work!
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't mean to be overly critical but are you sure you're going about this the best way, doing it all with lots of forms?
Why don't you have one form and have a servlet that then directs the flow of control to the appropriate method or another servlet, depending on which button was pressed?
That way you only need one form, one set of dates and you're even starting to do MVC design.
Adam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic