Meaningless Drivel is fun!*
The moose likes JSP and the fly likes retreive selected value  of list box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "retreive selected value  of list box" Watch "retreive selected value  of list box" New topic
Author

retreive selected value of list box

Mehak Darti
Greenhorn

Joined: Dec 13, 2003
Posts: 18
hi all..
i have this list box in which many values like 1250,1355, 7777, and so on values r going to be there. When i select on any of the values in the list box the page should be refereshed and below i have a another form where i want to display details on the basis of the value that i have selected.!!
For example.. i have employee number 500 .. and below i have a form that displays details for that employee .. like i want to pass a sql statement saying
(select * from emptable where empnum = '"+empnum+"') and empnum has the value 500 ... now how do i pass the value 500 to the varaible empnum and how do i know which value have i selected in the list box and on selection how do i refresh the page..??
so i want to know these 2 things...
1. onselection in the list box refresh the page
2. then retreive the selected value in a variable..!
any suggestionss...plz?
jyothsna kumari
Ranch Hand

Joined: Jul 21, 2003
Posts: 108
hia,
you can do something like this.
lets say u have a list box like this.
<SELECT size=2 id=select1 name=select1 onchange="call();" >
<OPTION value=1>1</OPTION>
<OPTION value=2>2</OPTION>
<OPTION value=3>3</OPTION>
and the function like this.
<SCRIPT LANGUAGE=javascript>
function call()
{
var x=document.frm1.select1.value ;
alert(x); //here 'x' gives the selected value
history.go(); //this refreshes the page
}
</SCRIPT>
hope this helps u.
Jyothsna
Mehak Darti
Greenhorn

Joined: Dec 13, 2003
Posts: 18
but then in my jsp the values which are going to come are gonna be dynamic ... so i can't give static value in the option value... how do i go about the dynamic values for the list box...???
Mehak Darti
Greenhorn

Joined: Dec 13, 2003
Posts: 18
Ok ... thanxs any way all..... my thing is done...!!!bye
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: retreive selected value of list box
 
Similar Threads
selecting an option in a select box from session variable
Struts 1.1: Help needed with html:select, html:options, html:optionsCollection
html Checkbox value not getting
List Box problem
Html Select - to make an option selected