Here is my code,I am adding and deleting value to multiple select box using java script .But when i pass to another page i am unalbe to get the select box selctes values i can get only the last selected value .
How could i do it.
My code
Code: Select all
<?
//echo $locusrid;
//echo $sname;
include "pathfile.php";
include "sqlcon.php";
echo "<html>\n";
echo "<head>\n";
echo "<title>POST ADMIN::UserManagement>>AllUser>>ModifyUser</title>\n";
echo "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n";
echo "<link href="".$csspath."default.css" rel="stylesheet" type="text/css">\n";
echo " <script language="JavaScript"> \n";
echo "function tim()\n";
echo " {\n";
echo " var entername=parseInt(document.f1.locexpdate.value);\n";
echo " var mont= parseInt(document.f1.selectm.value);\n";
echo " var yeath = parseInt(document.f1.selecty.value);\n";
echo " var datt = parseInt(document.f1.dat.value);\n";
echo " var moni = parseInt(document.f1.mon.value);\n";
echo " var year = parseInt(document.f1.year.value);\n";
echo " if(yeath < year)\n";
echo " {\n";
echo " alert("Enter Correct Year");\n";
echo " return false;\n";
echo " } \n";
echo " if((mont < moni)&&(yeath <= year))\n";
echo " {\n";
echo " alert("Enter Correct Month");\n";
echo " return false;\n";
echo " }\n";
echo " if((entername < datt)&&(yeath <= year)) \n";
echo " {\n";
echo " alert("Enter Correct Date");\n";
echo " return false;\n";
echo " }\n";
echo " if((document.f1.text1.value=="") || (document.f1.text2.value=="")|| (document.f1.text3.value=="") || (document.f1.text4.value=="")|| (document.f1.text5.value=="") || (document.f1.text6.value==""))\n";
echo " { \n";
echo " alert("Please Enter Empty Field ");\n";
echo " return false;\n";
echo " } \n";
echo " return true;\n";
echo " }\n";
echo " function conf()\n";
echo " {\n";
echo " return confirm("Are You Want To Delete");\n";
echo " }\n";
echo "function doIt() \n";
echo " {\n";
echo " var e = document.forms['f1'].elements;\n";
echo " var o = e['locsel'].options;\n";
echo " for ( var i = 0; i < o.length; i++ ) \n";
echo " {\n";
echo " \n";
echo " if (o[i].selected) \n";
echo " {\n";
echo " e['locsel1'].length = e['locsel1'].length+1; \n";
echo " var len = e['locsel1'].length-1;\n";
echo " \n";
echo " alert("***************");\n";
echo " alert(len);\n";
echo " var ss = o[i].text; \n";
echo " alert(ss); \n";
echo " \n";
echo " e['locsel1'].options[len].value = o[i].value;\n";
echo " e['locsel1'].options[len].text = ss;\n";
echo " alert(len);\n";
echo " e['locsel1'].selectedIndex = len; \n";
echo " \n";
echo " }\n";
echo " }\n";
echo " }\n";
echo " \n";
echo " function removeFromList() {\n";
echo " var e = document.forms['f1'].elements;\n";
echo " var listField = e['locsel1'];\n";
echo " alert(listField.length);\n";
echo " if ( listField.length == -1) { \n";
echo " alert("There are no values which can be removed!");\n";
echo " } else {\n";
echo " var selected = listField.selectedIndex;\n";
echo " if (selected == -1) {\n";
echo " alert("You must select an entry to be removed!");\n";
echo " } else { \n";
echo " var replaceTextArray = new Array(listField.length-1);\n";
echo " var replaceValueArray = new Array(listField.length-1);\n";
echo " for (var i = 0; i < listField.length; i++) {\n";
echo " if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }\n";
echo " if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }\n";
echo " if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }\n";
echo " if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }\n";
echo " }\n";
echo " listField.length = replaceTextArray.length; \n";
echo " for (i = 0; i < replaceTextArray.length; i++) { \n";
echo " listField.options[i].value = replaceValueArray[i];\n";
echo " listField.options[i].text = replaceTextArray[i];\n";
echo " }\n";
echo " } \n";
echo " } \n";
echo "}\n";
echo "</script> \n";
echo "</head>\n";
echo "<body onLoad="dd();" bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n";
echo " <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">\n";
echo " <tr valign="top">\n";
echo " <td>\n";
echo " <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#00000">\n";
echo " <tr valign="top">\n";
echo " <td height="10">\n";
//echo " <table width="47%" border="0" align="center" class="listcolournotopoverdis">\n";
//echo $locusrid;
include "header.php";
echo " <a href="".$pathconfig."adminscreen.cgi?sname=".$sname."" style="text-decoration:none">Home</a> »";
echo " <a href="".$pathconfig."userscreen.cgi?sname=".$sname."" style="text-decoration:none"> User </a>»\n";
echo " <a href="".$pathconfig."UserDetails.cgi?sname=".$sname."" style="text-decoration:none"> AllUser </a>»\n";
$sql_query="select usr.name,usr.empid,usr.username,usr.altmail,usr.quota,usr.expdate,usr.quota,usr.globalaccess,usr.description from userdetails as usr where userid=".$locusrid."\n";
//echo $sql_query;
$sql_query=mysql_query($sql_query,$con);
while($row=mysql_fetch_array($sql_query,MYSQL_ASSOC))
{
/*echo $row["name"];
echo $row["empid"];
echo $row["username"];
echo $row["altmail"];
echo $row["expdate"];
echo $row["quota"];
echo $row["globalaccess"];
echo $row["description"];*/
$datecheck = $row["expdate"];
echo "<form name="f1" method="get" action="".$pathconfig."modifyuser.php"> \n";
echo " <input type="hidden" name="locuserid" value="".$locusrid."">\n";
echo " <input type="hidden" name="sname" value="".$sname."">\n";
echo " <table width="57%" border="0" align="center">\n";
echo " <tr class="inboxrightleftvis">\n";
echo " <td colspan="2" align="center"> Edit/Delete User </td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td width="35%" class="adminTopNav">Name</td>\n";
echo " <td width="100%"><input name="locname" type="text" class="texftfield1by2" size="30" value="".$row["name"].""></td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Emp-Id</td>\n";
echo " <td><input name="locempid" type="text" class="texftfield1by2" size="30" value="".$row["empid"].""></td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Username</td>\n";
echo " <td><input name="locusername" type="text" class="texftfield1by3" size="30" readonly value="".$row["username"].""> \n";
echo " <span class="adminTextOnly">@Bandvalley.com</span> </td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Alt.Mail-Id</td>\n";
echo " <td> <input name="localtmail" type="text" class="texftfield1by2" size="30" value="".$row["altmail"].""></td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Group</td>\n";
$sql_group ="select g.groupname,gt.groupid from grouptrans as gt,groups as g where g.groupid=gt.groupid and gt.userid=$locusrid";
//$sql_group = "select g.groupname from groups as g";
//$sql_group = "select g.groupid from grouptrans as g where userid = $locusrid";
$qr1 = mysql_query($sql_group,$con) or die("Cannot open");
$rowvar = mysql_num_rows($qr1);
echo "<td class="listcolournotopoverdis">\n";
if($rowvar == 0)
{
echo " <table align="right" width="100%">\n";
echo " <tr>\n";
echo " <td width="17%">\n";
echo " <select name="locsel1" size="5" multiple>\n";
echo " <option >No Groups</option>\n";
echo " <input type="hidden" name="aaa">\n";
echo " </select> \n";
echo " </td>\n";
echo " <td width="20%">\n";
echo "<input type="button" value="REMOVE" onClick="removeFromList(this.value);">\n";
echo " </td>\n";
echo " <td width="13%">\n";
echo "<input type="button" value="ADD" onclick="doIt();" >\n";
echo " </td>\n";
$sql_all = "select groupname from groups ";
$qrall = mysql_query($sql_all,$con) or die("Cannot open");
$rowvarall = mysql_num_rows($qrall);
echo " <td width="50%">\n";
echo " <select name="locsel" size="5" multiple>\n";
while($rowsall = mysql_fetch_array($qrall,MYSQL_NUM))
{
echo " <option> ".$rowsall[0]."</option>\n";
}
echo " </select> \n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
}
else
{
//echo " <select name="locsel" class="texftfield1by2" style="width:100">";
//$sql_fetch = "select g.groupname,gt.groupid from grouptrans as gt,groups as g where g.groupid=gt.groupid and gt.userid='$locusrid'";
//echo $sql_fetch;
//$qqr1 = mysql_query($sql_fetch,$con) or die("Cannot open");
echo " <table align="right" width="100%">\n";
echo " <tr>\n";
echo " <td width="17%">\n";
echo " <select name="locsel1" size="5" multiple>\n";
while($rows = mysql_fetch_array($qr1,MYSQL_NUM))
{
//echo " <input type="hidden" name="hid">\n";
echo " <option >".$rows[0]."</option>\n";
echo " <input type="hidden" name="hide" value="".$rows[0]."">\n";
$i++;
}
echo " </select> \n";
echo " </td>\n";
echo " <td width="20%">\n";
echo "<input type="button" value="REMOVE" onClick="removeFromList(this.value);">\n";
echo " </td>\n";
echo " <td width="13%">\n";
echo "<input type="button" value="ADD" onclick="doIt();">\n";
echo " </td>\n";
$sql_all = "select groupname from groups ";
$qrall = mysql_query($sql_all,$con) or die("Cannot open");
$rowvarall = mysql_num_rows($qrall);
echo " <td width="50%">\n";
echo " <select name="locsel" size="5">\n";
while($rowsall = mysql_fetch_array($qrall,MYSQL_NUM))
{
echo " <option>".$rowsall[0]."</option>\n";
}
echo " </select> \n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
//echo "<input type="checkbox" name="loccheck[]" value="".$rows[0]."" checked>$rows[0]\n";
//echo " </select>\n";
}
echo "</td>\n";
/*
echo " <td><select name="select" class="downbutt">\n";
echo " </select></td>\n";*/
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Expiry Date</td>\n";
echo " <td> <select name="locexpdate" class="downbutt">\n";
list($year, $month, $date) = split('[/.-]', $datecheck);
echo "year: $year; Month: $month; Date: $date<br />\n";
$month1 = intval($month);
//echo "**************".$month1;
for($k=1;$k<32;$k++)
{
if($date==$k)
echo "<option value="".$k."" selected="".$k."">".$k."</option>\n";
else
echo "<option value="".$k."">".$k."</option>\n";
}
echo " </select> <select name="selectm" class="downbutt">\n";
$monarr = array(x,Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
//$monarr = "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
for($l=1;$l<=12;$l++)
{
if($month1==$l)
echo "<option value="".$l."" selected="".$l."">".$monarr[$l]."</option>\n";
else
echo "<option value="".$l."">".$monarr[$l]."</option>\n";
}
echo "</select> <select name="selecty" class="downbutt">\n";
for($m=2004;$m<2014;$m++)
{
if($year==$m)
echo "<option value="".$m."" selected="".$m."">".$m."</option>\n";
else
echo "<option value="".$m."">".$m."</option>\n";
}
echo " </select> </td>\n";
echo " </tr>\n";
$currdate = getdate();
$year1 = $currdate["year"];
$mon1 = $currdate["mon"];
$day1 = $currdate["mday"];
echo " <input type ="hidden" name="dat" value="".$day1."">\n";
echo " <input type ="hidden" name="mon" value="".$mon1."">\n";
echo " <input type ="hidden" name="year" value="".$year1."">\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Quota</td>\n";
echo " <td><input name="locquota" type="text" class="texftfield1by2" size="30" value="".$row["quota"].""></td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Global Address Access</td>\n";
echo " <td><select name="locglobalacess" class="downbutt">\n";
echo " <option value="n">No</option>\n";
echo " <option value="y" selected>Yes</option>\n";
echo " </select></td>\n";
echo " </tr>\n";
echo " <tr class="listcolournotopoverdis"> \n";
echo " <td class="adminTopNav">Description</td>\n";
echo " <td><input name="locdescription" type="text" class="texftfield1by2" size="30" value="".$row["description"].""></td>\n";
echo " </tr>\n";
echo " <tr align="center" valign="middle" class="listcolournotopoverdis"> \n";
echo " <td><div align="left"> </div></td>\n";
echo " <td><div align="left">\n";
//echo " <input type="hidden" value=""<<query<<"" name="fileid">\n";
//echo " <input type="hidden" value="<<sname<<" name="sname">\n";
echo " <input name="del" type="submit" class="button" value="Modify" onClick=" return tim();">\n";
//echo " </form>\n";
//echo "<form name="f1" method="get" action="http://linuxserver/cgi-bin/arun/DeleteUser.cgi"> \n";
echo " <input name="del" type="submit" class="button" value="Delete" onClick="return conf();">\n";
//echo " <input type="hidden" value="<<username<<" name="nam1">\n";
echo " </div></td>\n";
echo " </tr>\n";
}
echo " </table>\n";
echo " </form>\n";
echo " </table>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr valign="bottom">\n";
echo " <td>\n";
echo "<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">\n";
include "footer.php";
echo "</table>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</body>\n";
echo "</html>";
?>Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]