By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,806 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,806 IT Pros & Developers. It's quick & easy.

Problem to transfer multiple value from select box

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

<head>

<script language="JavaScript">
function addSrcToDestList() {

destList1 = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList1.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[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.options[count] != null) {
if (srcList.options[i].text == destList1.options[count].text) {
found = true;
break;
}
}
}

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

// Deletes from the destination list.
function deleteFromDestList() {
var destList1 = window.document.forms[0].destList;
var len = destList1.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) {
destList1.options[i] = null;
}
}
}


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

</SCRIPT>
</head>

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

<select name="srcList" multiple size=10 style="width:150;" onChange="moveOver();">
<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="javascript:addSrcToDestList()">
<br>
<br>
<input type="button" value=" << " onClick="javascript:deleteFromDestList();">

<select name="destList[]" size=10 style="width:150;" 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
Share this Question
Share on Google+
3 Replies


100+
P: 268
Hi run this code its working fine

<script language="JavaScript">
function addSrcToDestList() {

destList1 = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList1.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[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.options[count] != null) {
if (srcList.options[i].text == destList1.options[count].text) {
found = true;
break;
}
}
}

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

// Deletes from the destination list.
function deleteFromDestList() {
var destList1 = window.document.forms[0].destList;
var len = destList1.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) {
destList1.options[i] = null;
}
}
}


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

</SCRIPT>
<html>

</head>

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

<select name="srcList" multiple size=10 style="width:150;" >
<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="javascript:addSrcToDestList()">
<br>
<br>
<input type="button" value=" << " onClick="javascript:deleteFromDestList();">

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

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

</body>
</html>
Aug 29 '06 #2

P: 9
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="JavaScript">
function addSrcToDestList() {

destList1 = window.document.forms[0].destList;
srcList = window.document.forms[0].srcList;
var len = destList1.length;
for(var i = 0; i < srcList.length; i++) {
if ((srcList.options[i] != null) && (srcList.options[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.options[count] != null) {
if (srcList.options[i].text == destList1.options[count].text) {
found = true;
break;
}
}
}

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

// Deletes from the destination list.
function deleteFromDestList() {
var destList1 = window.document.forms[0].destList;
var len = destList1.options.length;
for(var i = (len-1); i >= 0; i--) {
if ((destList1.options[i] != null) && (destList1.options[i].selected == true)) {
destList1.options[i] = null;
}
}
}


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

</SCRIPT>
</head>

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

<select name="srcList" multiple size=10 style="width:150;" onChange="moveOver();">
<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="javascript:addSrcToDestList()">
<br>
<br>
<input type="button" value=" << " onClick="javascript:deleteFromDestList();">

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

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

</body>


PHP page: process.php
<?
$result2 = mysql_query("insert 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

P: 1
Hi,

Just use

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

It will work.
Feb 13 '07 #4

Post your reply

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