473,573 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem to transfer multiple value from select box

9 New Member
This is my first problem.Please help me.
I have the following code:

<head>

<script language="JavaS cript">
function addSrcToDestLis t() {

destList1 = window.document .forms[0].destList;
srcList = window.document .forms[0].srcList;
var len = destList1.lengt h;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.optio ns[i] != null) && (srcList.option s[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList1.opti ons[count] != null) {
if (srcList.option s[i].text == destList1.optio ns[count].text) {
found = true;
break;
}
}
}

if (found != true) {
destList1.optio ns[len] = new Option(srcList. options[i].text);
len++;
}
}
}
}

// Deletes from the destination list.
function deleteFromDestL ist() {
var destList1 = window.document .forms[0].destList;
var len = destList1.optio ns.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.opt ions[i] != null) && (destList1.opti ons[i].selected == true)) {
destList1.optio ns[i] = null;
}
}
}


function allSelect()
{
List = document.forms[0].destList;
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.len gth;i++)
{
List.options[i].selected = true;
}
}

</SCRIPT>
</head>

<body>
<form name="upload" id="upload" ENCTYPE="multip art/form-data" method="POST" action="<?php $_SERVER['PHP_SELF']?>" onSubmit="allSe lect();">

<select name="srcList" multiple size=10 style="width:15 0;" onChange="moveO ver();">
<option value ="0" >Admin</option>
<option value ="1" >Public</option>
<option value ="2" >Private</option>
<option value ="3" >All</option>
</select>

<input type="button" value=" >> " onClick="javasc ript:addSrcToDe stList()">
<br>
<br>
<input type="button" value=" << " onClick="javasc ript:deleteFrom DestList();">

<select name="destList[]" size=10 style="width:15 0;" multiple >
</select>

<input type="submit" class="button3" name="upload" value="Insert" >

</body>

I need to transfer multiple value from select box "destList[]".So I use the array type name.But problem arises when I want to use this name in head section java script.Here I can not use array type "destList[]" select box name.Here I have option to use the select box name "destList" not "destList[]". The head section java script use to transfer list from one select box to another.

The select box (destList[]) hold the data from another selectbox (srcList) and transfer the data to a PHP page. So how can I solve the selectbox name problem?

Thanks in advance.
Aug 29 '06 #1
3 12543
vssp
268 Contributor
Hi run this code its working fine

<script language="JavaS cript">
function addSrcToDestLis t() {

destList1 = window.document .forms[0].destList;
srcList = window.document .forms[0].srcList;
var len = destList1.lengt h;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.optio ns[i] != null) && (srcList.option s[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList1.opti ons[count] != null) {
if (srcList.option s[i].text == destList1.optio ns[count].text) {
found = true;
break;
}
}
}

if (found != true) {
destList1.optio ns[len] = new Option(srcList. options[i].text);
len++;
}
}
}
}

// Deletes from the destination list.
function deleteFromDestL ist() {
var destList1 = window.document .forms[0].destList;
var len = destList1.optio ns.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.opt ions[i] != null) && (destList1.opti ons[i].selected == true)) {
destList1.optio ns[i] = null;
}
}
}


function allSelect()
{
List = document.forms[0].destList;
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.len gth;i++)
{
List.options[i].selected = true;
}
}

</SCRIPT>
<html>

</head>

<body>
<form name="upload" id="upload" ENCTYPE="multip art/form-data" method="POST" action="<?php $_SERVER['PHP_SELF']?>" onSubmit="allSe lect();">

<select name="srcList" multiple size=10 style="width:15 0;" >
<option value ="0" >Admin</option>
<option value ="1" >Public</option>
<option value ="2" >Private</option>
<option value ="3" >All</option>
</select>

<input type="button" value=" >> " onClick="javasc ript:addSrcToDe stList()">
<br>
<br>
<input type="button" value=" << " onClick="javasc ript:deleteFrom DestList();">

<select name="destList" size=10 style="width:15 0;" multiple >
</select>

<input type="submit" class="button3" name="upload" value="Insert" >

</body>
</html>
Aug 29 '06 #2
imrantbd
9 New Member
Thank you vssp.

I have try your solution.This is a way.But I need array type
name like "destList[]" must use for my destlist select box,not a single name.Or need a solution to capture multiple value of "destList[]" select box and send all selected value in php page.The multiple select value then insert in database added by comma.Again the following is my code:

Form Page:form.php

<head>
<script language="JavaS cript">
function addSrcToDestLis t() {

destList1 = window.document .forms[0].destList;
srcList = window.document .forms[0].srcList;
var len = destList1.lengt h;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.optio ns[i] != null) && (srcList.option s[i].selected)) {
//Check if this value already exist in the destList or not
//if not then add it otherwise do not add it.
var found = false;
for(var count = 0; count < len; count++) {
if (destList1.opti ons[count] != null) {
if (srcList.option s[i].text == destList1.optio ns[count].text) {
found = true;
break;
}
}
}

if (found != true) {
destList1.optio ns[len] = new Option(srcList. options[i].text);
len++;
}
}
}
}

// Deletes from the destination list.
function deleteFromDestL ist() {
var destList1 = window.document .forms[0].destList;
var len = destList1.optio ns.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.opt ions[i] != null) && (destList1.opti ons[i].selected == true)) {
destList1.optio ns[i] = null;
}
}
}


function allSelect()
{
List = document.forms[0].destList;
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.len gth;i++)
{
List.options[i].selected = true;
}
}

</SCRIPT>
</head>

<body>
<form name="upload" id="upload" ENCTYPE="multip art/form-data" method="POST" action="<?php $_SERVER['PHP_SELF']?>" onSubmit="allSe lect();">

<select name="srcList" multiple size=10 style="width:15 0;" onChange="moveO ver();">
<option value ="0" >Admin</option>
<option value ="1" >Public</option>
<option value ="2" >Private</option>
<option value ="3" >All</option>
</select>

<input type="button" value=" >> " onClick="javasc ript:addSrcToDe stList()">
<br>
<br>
<input type="button" value=" << " onClick="javasc ript:deleteFrom DestList();">

<select name="destList[]" size=10 style="width:15 0;" multiple >
</select>

<input type="submit" class="button3" name="upload" value="Insert" >

</body>


PHP page: process.php
<?
$result2 = mysql_query("in sert into
ccms_table values(' " . join(",",$_POST["destList"]) ." ' ) );
?>


if I use the name "destList" then I can not transfer & capture multiple value in php page.So I need "destList[]" type name in select box.On the other hand if I use "destList[]" I can transfer multi value but the array type name "destList[]" does not work in java script code.This is my main problem.On java script side I need to use single name like "destList" & on PHP side I need to use array type name like "destList[]".

Please give the solution.Thanks to all again.
Aug 31 '06 #3
napsguy
1 New Member
Hi,

Just use

<select name="destList[]" ID="destList" size=10 style="width:15 0;" multiple >

It will work.
Feb 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7708
by: Rolf Wester | last post by:
Hi, I have a form with a select element with multiple="true". When using the GET method (I suppose the same happens with the POST method) I can seen that the form sends channels=CH1&channels=CH2 when CH1 and CH2 have been choosen. $_GET gives me "CH2". Is there any way to get all the choosen channels elements? I would be very appreciative...
7
2842
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID);...
5
6806
by: carrajo | last post by:
Hey, I'm trying to duplicate the following: Select List 1 --- Apple Orange Banana
2
1320
by: Griff | last post by:
Hi I have an HTML search page that contains a drop-down box with approximately 78,000 items in it. The actual content of this select box varies depending upon some of the parameters a user has chosen, so this needs to be loaded (possibly several times as they change their parameters) and I've got this working using AJAX.
3
8708
by: imrantbd | last post by:
I need array type name like "destList" must use for my destlist select box,not a single name.Or need a solution to capture multiple value of "destList" select box and send all selected value in php page.The multiple select value then insert in database added by comma.The following is my code: Form Page:form.php <head> <script...
2
13788
by: Steven | last post by:
I have a page(pg1) which contains a select list (list1) in a form(form1) and an iframe(frame1), in this iframe is a page(pg2) with another select list(list2) in a form(form2) and I transfer the contents of list2 to list 1 as follows function transfer(){ for (var i=0; i<document.form2.list2.length; i++){ var cf=document.form2.list2;...
10
3317
by: ellie2905 | last post by:
Hello, I am new to this forum and I am glad I found it because it seems that it will help me with my problem.I have creates a site using jsf components like grid panels and buttons.In the mozilla firefox browser the components are shown just as they are supposed to, but in internet explorer my button stretches to the right until the end of the...
58
8031
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast...
2
3003
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
0
7776
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7686
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8014
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7771
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5581
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5289
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2197
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1297
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1038
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.