Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Multiple select box
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


premika
Multiple select box
2 Answer(s)      3 years and 7 months ago
Posted in : JSP-Servlet


Hi, I need help in code for multiple select box. The multiple select box should be populated with the db values.The selection done in the multiple select box is to be moved to the text area provided a add and remove buttons in between for moving the selected items into the text area.


Advertisement
View Answers

April 11, 2011 at 4:55 PM


<%@page import="java.sql.*"%>
<script>
var array = new Array();
function add() {
    var i=0;
    var ob=document.form.select;
    while(ob.selectedIndex != -1) {
        array.push(ob.options[ob.selectedIndex].value); 
        ob.options[ob.selectedIndex].selected = false;
        }
        for( i=0;i<array.length;i++){
        form.text.value+=array[i]+"\n";
        }
}
function remove(){
form.text.value="";
}

</script>
<form name="form">
<pre>
<select name="select" multiple>
<%
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 ResultSet rs = stmt.executeQuery("Select * from employee");
 while(rs.next()){
%>
<option value="<%=rs.getString("name")%>"><%=rs.getString("name")%></option>
<%
 }
%>
</select>
<textarea rows="5" cols="20" name="text">


April 11, 2011 at 7:10 PM


<!DOCTYPE html>
<html>
<head>
  <style>
  div {
  color:red;
  }
  </style>
  <script src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
&lt;SCRIPT LANGUAGE="JAVASCRIPT">

$(function() {
  $(".low input[type='button']").click(function(){
    var arr = $(this).attr("name").split("2");
    var from = arr[0];
    var to = arr[1];
    $("#" + from + " option:selected").each(function(){
      $("#" + to).append($(this).clone());
      $(this).remove();
    });
  });
})

</SCRIPT> 
<body>

<table>
<tr>
<td>
 <div class="container">
    <select name="itemsToChoose" id="left" size="8" multiple="multiple">
      <option value="1">item1</option>
      <option value="2">item2</option>
      <option value="3">item3</option>
      <option value="4">item4</option>
      <option value="5">item5</option>
    </select>
  </div>
</td>
<td>
  <div class="low container">
    <input name="left2right" value="add" type="button">
    <input name="right2left" value="remove" type="button">
  </div>
</td>
<td>
  <div class="container">
    <select name="itemsToAdd" id="right" size="8" multiple="multiple">
    </select>
  </div> 
</td>
</tr>
</table>

</body>
</html>

Try this....This works.....Download the js file by copy and pasting the js url in the address bar.



Related Tutorials/Questions & Answers:
Multiple select box
Multiple select box  Hi, I need help in code for multiple select box. The multiple select box should be populated with the db values.The selection done in the multiple select box is to be moved to the text area provided a add
i want to select a multiple value of check box by using onclick or onchange event without using from submission
i want to select a multiple value of check box by using onclick or onchange event without using from submission   i have 4 check box name 1)profile... the result is ok but after getting value of first box now i want a result of second box
Advertisements
multiple select values
multiple select values   can you provide an example for multiple select values for html:select tag
struts2 select tag multiple
struts2 select tag multiple  struts2 select tag multiple
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
query regarding multiple select
query regarding multiple select  i have a select in jsp with multiple options.When i select multiple values i am not able to insert it into database and how do i retrieve them..please help me with an example code
Select Box question
Select Box question   hello guys, i want to display data in a select box using foreign key,those data will come from other table which which is parent, that form will be in HTML(web ). i use oracle as database and i want using
Dynamic select box - Ajax
in the other select box automatically.. The city details must be extracted from...Dynamic select box  Hi, I Have almost completed the task... select boxes in my page.. One is "Select a Country" and other one is "Select
dynamic select box
dynamic select box  thank u my dear friend.but i have a code like...> <select name="city"> <option>city</option>...) die("access failed"); $select=mysql_select_db("vtigercrm530"); if(!$select
dynamic select box
dynamic select box  hello friends i created a form and details of city & locations have to be come from database. if city hyderabad chosen then locations of hyderabad only appear in location selectbox.plz send code it is more
mysql select from multiple tables
mysql select from multiple tables   how can i select the date field from multiple tables in mysql?   "UNION" can be used to select data from multiple tables in my sql... for example (SELECT * from name where `name
How to change focus among multiple select boxes?
How to change focus among multiple select boxes?  Hello, I have three select boxes in three divs. All of the select boxes are focused when I click them one after the other. I want only one select box to be focused at a time
Select Box Validation in JavaScript
Select Box Validation in JavaScript In this section we will discuss about select box validation in JavaScript. Select box allows you to create drop down list... options. HTML select Box having same functionality as HTML Checkbox Fields
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing a project on struts2 in which i have a jsp page which has two select boxes like Now i want to use ajax so that when i select a district value
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing a project on struts2 in which i have a jsp page which has two select boxes like <... it by assigning to the block list select box. so please help me..its urgent
display from select box - JSP-Servlet
display from select box  I am doing a jsp project. In this jsp project i have to show the photos in one cell depending on the selection from other selection box which is in the same page. The photos are stored
Multiple select dropdown with Ajax
Multiple select dropdown with Ajax This tutorial explains how to create...; <li><a href="mutipledropdown">Multiple Select.... This file used for displays all multiple select dropdown.The code of "
retaining the selected values in html:select multiple="true" in jsp + collection + struts
retaining the selected values in html:select multiple="true" in jsp + collection + struts  Hi, I have a multiple selection box in one of the jsp...;strong> <html:select multiple="true" style="width
Passing Multi select list box values using ajax to get values to dependent list box
Passing Multi select list box values using ajax to get values to dependent list... with multiple selection. How can i pass multiple selected values through ajax to retrieve the dependent values to the immediate next list box. Please help me
jQuery Multiple Checkbox Select / Deselect
$(function(){ // add multiple select / deselect functionality..."); } }); }); jQuery Multiple Checkbox Select / Deselect In this section, you will learn how to create multiple checkbox group which select/deselect the group
how to display(update) current date and month in select box on selecting the year.
how to display(update) current date and month in select box on selecting the year.  how to display(update) current date and month in select box on selecting the year
How to implement ajax in struts2 to operate on select box in jsp
How to implement ajax in struts2 to operate on select box in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes... by assigning to block list select box... plz help me .. its urgent .. thanx in advance
jQuery change event with multiple select option
jQuery change event with multiple select option In this tutorial , we will discuss about 'change' event of jQuery with multiple select list & it also display the selected option. In the below example a multiple select list
Use of Select Box to show the data from database
Use of Select Box to show the data from database       Example program using Select Box to show retrieved data from database This example will describe you the use of Select Box in a JSP
How to write a select box and id should be stored in database?
How to write a select box and id should be stored in database?  Hi, How to write a select box and select the name(devi) regarding name id(like 60...); JLabel lab=new JLabel("Select Name:"); final JComboBox combo
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using QTP
Not Able to select an Item in Spark Combo Box control (Adobe Flex Object) using... Flex controls. But i am not able to select any item from Spark Combo Box. I tied using .Open (Its not opening the drop down list) , also i tried using Select
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only... added select box also into next jsp page plz reply me as early as posssible
select one item name throug combo box than other combobox show item price
select one item name throug combo box than other combobox show item price  i have one table in database item master..if i select one item name through combo box than other combobox show item price only select item name... how i
sir plz help in design a jsp page whichis as follow username [_____] select [__>]password [_____] after selection then onlypassword text box is visible
sir plz help in design a jsp page   sir plz help in design a jsp page which is as follow username [ _ ] select [ > ] password [ _ ] after selection then only password text box is visible
jQuery 'select' form event
input box. In this Example, two input text box are given , when we select...; Click and drag the mouse to select text in the input box. </p>...jQuery 'select' form event In this tutorial, we will discuss about
 

 

 

DMCA.com