permaculture playing cards*
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
Author

post form data when slection changed in list

Ben Weng
Greenhorn

Joined: Feb 22, 2005
Posts: 19
Hi,
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?

[code]
...
<form name="myform">
...
<select>
<option value="selected 1">choose me</option>
<option value="selected 2">no, choose me</option>
</select>
...
<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">
...
</form>
...
[code]

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.

newbie.


-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
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

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

onchange="document.FormName.submit()"

Eric
 
Don't get me started about those stupid light bulbs.
 
subject: post form data when slection changed in list
 
Similar Threads
Issue with displaying data back on the page
Show a hidden text field
pass the value to next form
Problem in Selecting values from select tag
How to retain drop-down list value after submit?