File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes post form data when slection changed in list 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 "post form data when slection changed in list" Watch "post form data when slection changed in list" New topic

post form data when slection changed in list

Ben Weng

Joined: Feb 22, 2005
Posts: 19
I've read bunch of posts here regarding related issues but I could not find the answer to this:

I have a drop list, bunch of fields, how do I do to submit the form just by selecting one of the items in the list?

<form name="myform">
<option value="selected 1">choose me</option>
<option value="selected 2">no, choose me</option>
<input type="text" size="20">
<input name="create" type="submit" id="create" VALUE="Create a dummy">
<input name="update" type="submit" id="update" VALUE="Update the dummy">

The form is generated by a servlet. What I want to do now is that when user selects one of the options, a request is sent to the server and another servlet would take care of filling the text field and send the form back to user.

Also, notice that I have two buttons down there and how would the servlet know which button is clicked?

Thanks for any inputs.


-Ben<br />SCJP/SCJD 1.4<br />Certified Sybase DBA
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
What about having a single controller, a servlet, and let the controller delegates the task, either update or create, to a model.
Ben Weng

Joined: Feb 22, 2005
Posts: 19
Sorry I had two questions posted in my first post.
One is how do I post data by slecting a item in the drop down list. A form has attribute called "action", how about "select"?
Two is what Joe responded to. And how, then would the single controller know which button the user clicked? I mean, in a regular java app, we can always associate a action command with buttons. what about in servlet? Would you be more specific, Joe?

thanks a lot.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63857

Yes, it's best not to ask multiple questions in one post. One or the other can get lost in the shuffle, and it makes reading through any replies confusing.

To your first question, you can use Javascript to submit the request when the select element is changed.

To the second, you can assign a request parameter that is unique to each button to be able to distinguish which was pressed. Or better yet, if the buttons trigger different actions, they should submit themselves to different controller servlets.

In any case, this isn't a JSP issue as much as an HTML and Javascript issue so this has been moved to the HTML/Javascript forum.

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
To submit the form...


I agree. Here's the link:
subject: post form data when slection changed in list
It's not a secret anymore!