Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Submit Methods pulling same data

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • 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.
 
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
Mac OS X IntelliJ IDE Chrome
  • 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
Mac OS X IntelliJ IDE Chrome
  • 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
Mac OS X IntelliJ IDE Chrome
  • 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
 
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!
 
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
 
I don't always make ads but when I do they're tiny
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic