File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes onchange event of drop down list  - problem F1 pls Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "onchange event of drop down list  - problem F1 pls" Watch "onchange event of drop down list  - problem F1 pls" New topic

onchange event of drop down list - problem F1 pls

river down

Joined: Dec 11, 2002
Posts: 21
I have a drop down list from the JSP and here are the scenarios:
say I have values for the drop down as: (example)
By defualt upon initial loading of the JSP the value will be UPDATE.....since I used the "onchange event" of the drop down list nothing happen when the user choose the same defualt values..unless I choose other values say "DELETE" then choose "UPDATE" back again then it works.....
1) choose default value....nothing happen
2) I choose values other than default... it works
3) I choose again the defualt work...
I cannot eliminate putting a defualt values to the dropdown upon loading
Can someone help on any event or ways possible that even if i choose the default values of the dropdown it will still perform the javascript function I want....
Thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

This is hardly a JSP question. You'd probably get more responses if you had a sheriff move this to the HTML/Javascript forum.

[Asking smart questions] [About Bear] [Books by Bear]
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
A cheap and easy workaround for this is to add a blank or informational option to the beginning of your list:
<option value="">
<option value="update">-UPDATE-
<option value="save">-SAVE-
<option value="delete">-DELETE-
<option value="">Select a task:
<option value="update">-UPDATE-
<option value="save">-SAVE-
<option value="delete">-DELETE-
river down

Joined: Dec 11, 2002
Posts: 21
Regarding my problem..instead of using a blank the defualt values will appear on the drop down upon loading of the is required that the drop down will only contain all valid values and not a blank....
Pls feel free to ask i u need some other clarifications...:-)
Meidi Novel

Joined: Dec 13, 2002
Posts: 2
The problem i think is, u the page is not loaded with the default value..u are calling the same page on onChange event of the list..

i think this code will be useful
<select name="" onChange="..">
<option value="s">Save</option>
<option value="u">Update</option>
<option value="d">Delete</option>
//as u know the default value is Save,the remaining program can be written with value="Save"...
String s = "Save";
if(request.getParameter("selectoption") != null)
s = "Save";
// so in the first case, the request.getParameter("selectoption") would be null, then the value of s will be default value ie, "Save"...

i hope this explanation helps u..
I agree. Here's the link:
subject: onchange event of drop down list - problem F1 pls
jQuery in Action, 3rd edition