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
PHP page: process.php
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 advance.
Form Page:form.php
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>
Code:
<?
$result2 = mysql_query("insert into
ccms_table values(' " . join(",",$_POST["destList"]) ." ' ) );
?>
Please give the solution.Thanks to all advance.
Comment