wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Submit Methods pulling same data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Submit Methods pulling same data" Watch "Submit Methods pulling same data" New topic
Author

Submit Methods pulling same data

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jun 27, 2001
Posts: 171
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Brian, you are the man!! Thanks a mill.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Aug 15, 2001
Posts: 65
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

Joined: Oct 09, 2001
Posts: 566
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 have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
 
 
subject: Submit Methods pulling same data