How to achieve the following functions

Source: Internet
Author: User
Tags eval functions php code query split
PHP Code:--------------------------------------------------------------------------------
Script Description:
Add the following code to the <body> area
<script language= "JavaScript" >
<!--Begin
OldValue = "";
function Passtext (passedvalue) {
if (Passedvalue!= "") {
var totalvalue = passedvalue+ "\ n" +oldvalue;
Document.displayform.itemsbox.value = Totalvalue;
OldValue = Document.displayform.itemsbox.value;
}
}
End-->
</script>
<form name= "Selectform" >
<select name= "Dropdownbox" size=1>
<option value= "" > Please select </option>
<option value= "first item" > First item </option>
<option value= "Second Item" > Second item </option>
<option value= "Third item" > Third item </option>
<option value= "Fourth" > Fourth item </option>
<option value= "Fifth" > Fifth item </option>
<option value= "Sixth" > Sixth item </option>
</select>
<input Type=button value= "Add to List" onclick= Passtext (this.form.dropdownbox.options[ This.form.dropdownbox.selectedindex].value); " >
</form>
<form name= "DisplayForm" >
<font face= "Arial, Helvetica, Sans Serif" size= "3" ><b> you can choose your own:</b></font><br>
<textarea cols= "rows=" 5 "name=" Itemsbox ">

PHP Code:--------------------------------------------------------------------------------
Script Description:
Add the following code to the <body> area
<script language= "JavaScript" >
<!--Begin
var delimiter = ":";
function Moveoption (Movefrom, MoveTo, ToDo) {
var selectfrom = eval (' Document.main_form. ') +movefrom);
var Selectto = eval (' Document.main_form. ') +moveto);
var selectedindex = SelectFrom.options.selectedIndex;
var container;
if (todo== ' Add ') {
Container=eval (' Document.main_form. ') +todo+moveto);
}
if (todo== ' Remove ') {
Container=eval (' Document.main_form. ') +todo+movefrom);
}
if (SelectedIndex = = 1) {
Alert ("Please select a user");
} else {
For (i=0 i<selectfrom.options.length; i++) {
if (selectfrom.options[i].selected) {
var name = Selectfrom.options[i].text;
var ID = Selectfrom.options[i].value;
Selectfrom.options[i] = null;
Selectto.options[selectto.options.length]=new Option (Name,id);
I=i-1;
if (todo== ' Add ' | | todo== ' Remove ') {
Container.value=container.value+name+delimiter;
Container.value=container.value+id+delimiter;
}
}
}
}
}
function Checkduplicates (Addlistcontainer, Removelistcontainer) {
var addlist = eval (' Document.main_form. ') +addlistcontainer);
var removelist = eval (' Document.main_form. ') +removelistcontainer);
var tempaddlist = Addlist.value;
var tempremovelist = Removelist.value;
if (tempaddlist> ' &&TempRemoveList> ') {
Tempaddlist = tempaddlist.substring (0,tempaddlist.length-1);
Tempremovelist = tempremovelist.substring (0,tempremovelist.length-1);
var AddArray = Tempaddlist.split (delimiter);
var Removearray = Tempremovelist.split (delimiter);
For (i=0 i<addarray.length; i++) {
For (j=0 j<removearray.length; j + +) {
if (Addarray[i]==removearray[j]) {
Addarray[i]= ';
Removearray[j]= ';
Break
}
}
}
Addlist.value= ';
For (i=0 i<addarray.length; i++) {
if (addarray[i]> ') {
Addlist.value = Addlist.value + addarray[i] + delimiter;
}
}
Removelist.value= ';
For (i=0 i<removearray.length; i++) {
if (removearray[i]> ') {
Removelist.value = Removelist.value + removearray[i] + delimiter;
}
}
}
}
function Lockchanges () {
Checkduplicates (' Addadmins ', ' removeadmins ');
Checkduplicates (' addusers ', ' removeusers ');
}
End-->
</script>
<table align= "center" >
<tr><td>
<form name=main_form action= "" Method=post><input Type=hidden name=addadmins>
<input type=hidden name=removeadmins> <input Type=hidden name=addusers>
Type=hidden name=removeusers>
<div align= "center" >
<table cellspacing= "0" cellpadding= "5" border= "0" >
<tbody>
<tr>
&LT;TD valign= "Top" align= "Middle" rowspan= "2" > Alternative user <br><select multiple size= "" Name= "Employees" >
<option>employee_01<option>employee_02<option>employee_03<option>employee_04<option >Employee_05<option>Employee_06<option>Employee_07<option>Employee_08<option> Employee_09<option>employee_10</option></select>
</td>
<td>
<p align= "center" ><input onclick= "moveoption" (' Employees ', ' Admins ', ' Add '); "type=" button "value=" Add admin >> "name=add_admin>
</p>
<p align= "center" ><input onclick= moveoption (' Admins ', ' Employees ', ' Remove '); "type=" button "value=" < < Delete admin "name=" Remove_admin >
</p></td>
&LT;TD valign= "Top" align= "middle" >administrators<br><select multiple size= "5" name= "Admins" >
<option>admin_01<option>admin_02<option>admin_03<option>admin_04<option>admin_05 </option></select>
</td></tr>
<tr>
<td>
<p align= "center" ><input onclick= moveoption (' Employees ', ' Users ', ' Add '); "type=" button "value=" Add user > > "name=add_user>
</p>
<p align= "center" ><input onclick= moveoption (' Users ', ' Employees ', ' Remove '); "type=" button "value=" < < delete user "name=" Remove_user >
</p></td>
&LT;TD valign= "Top" align= "middle" >users<br><select multiple size= "5" name= "Users" >
<option>user_01<option>user_02<option>user_03<option>user_04<option>user_05</ Option></select>
</td></tr>
</tbody>
</table>
</div>
</FORM>
</td></tr>
<tr><td>
<div align= "center" ><input onclick= "lockchanges ();" type= "button" value= "Save Changes" ></div>
<BR>
<div align= "center" >
<a href= "Java Script:alert (document.main_form. Addadmins.value); " > Query for increased admin</a>
<br>
<a href= "Java Script:alert (document.main_form. Removeadmins.value); " > Query deletion of admin</a>
<br>
<a href= "Java Script:alert (document.main_form. Addusers.value); " > Query for increased user</a>
<br>
<a href= "Java Script:alert (document.main_form. Removeusers.value); " > Query deletion of user</a>
</div>
</td></tr>
</td></tr>
</table>


PHP Code:--------------------------------------------------------------------------------
Script Description:
Add the following code to the <body> area:
<script language= "JavaScript" >

<!--Begin
Sortitems = 1; Automatically sort items within lists? (1 or 0)

function Move (Fbox,tbox) {
for (var i=0; i<fbox.options.length; i++) {
if (fbox.options[i].selected && fbox.options[i].value!= "") {
var no = new Option ();
No.value = Fbox.options[i].value;
No.text = Fbox.options[i].text;
Tbox.options[tbox.options.length] = no;
Fbox.options[i].value = "";
Fbox.options[i].text = "";
}
}
Bumpup (Fbox);
if (sortitems) SORTD (Tbox);
}
function Bumpup (box) {
for (var i=0; i<box.options.length; i++) {
if (Box.options[i].value = = "") {
for (Var j=i j<box.options.length-1; J + +) {
Box.options[j].value = Box.options[j+1].value;
Box.options[j].text = Box.options[j+1].text;
}
var ln = i;
Break
}
}
if (ln < box.options.length) {
Box.options.length-= 1;
Bumpup (box);
}
}

function sortd (box) {
var temp_opts = new Array ();
var temp = new Object ();
for (var i=0; i<box.options.length; i++) {
Temp_opts[i] = box.options[i];
}
for (var x=0; x<temp_opts.length-1; x + +) {
For (Var y= (x+1); y<temp_opts.length; y++) {
if (Temp_opts[x].text > Temp_opts[y].text) {
temp = Temp_opts[x].text;
Temp_opts[x].text = Temp_opts[y].text;
Temp_opts[y].text = temp;
temp = Temp_opts[x].value;
Temp_opts[x].value = Temp_opts[y].value;
Temp_opts[y].value = temp;
}
}
}
for (var i=0; i<box.options.length; i++) {
Box.options[i].value = Temp_opts[i].value;
Box.options[i].text = Temp_opts[i].text;
}
}
End-->
</script>

<form action= "" method= "POST" >
<table border= "0" >
<tr>
<td><select multiple size= "5" name= "List1" >
<option value= "One" > Item 1.1 </option>
<option value= "A" > Item 1.2 </option>
<option value= "" > Item 1.3 </option>
</select></td>
<td>
<input type= "button" value= ">>" onclick= "Move (this.form.list1,this.form.list2)" Name= "B1" ><br>
<input type= "button" value= "<<" onclick= "Move (this.form.list2,this.form.list1)" Name= "B2" >
</td>
<td><select multiple size= "5" name= "List2" >
<option value= > Item 2.1 </option>
<option value= > Item 2.2 </option>
<option value= > Item 2.3 </option>
</select></td>
</tr>
</table>
</form>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.