Click to See Complete Forum and Search --> : [RESOLVED] Copy data from one select to another


DedoMraz
01-15-2008, 07:13 AM
Hello all.

How can I copy selected data from select1 to select2 by pressing the "add" button.
Can I make this somehow without refreshing the page? (javascript, ajax etc.)

theelectricwiz
01-18-2008, 09:22 AM
Hello. It can be done using javascript/ajax, but if you are wanting for the copy to show up on the page it may be easier just to refresh the page as you will have to copy a lot of items back and forth. To send the actual copy command you need to send the information required for the copy command to a php script as a get query in the link you request through ajax. eg something like.....


[CODE]
if (window.XMLHttpRequest) { // code for Mozilla, etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=succFunction;
xmlhttp.open("GET","http://localhost/copy.php?table=blah&items=1,2,3,6",true);
xmlhttp.send(null);
} else if (window.ActiveXObject) { // code for IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp) {
xmlhttp.onreadystatechange=succFunction;
xmlhttp.open("GET","http://localhost/copy.php?table=blah&items=1,2,3,6",true);
xmlhttp.send();
}
}

Hope that helps.

Cheers.

DedoMraz
01-18-2008, 10:10 AM
Hello. It can be done using javascript/ajax, but if you are wanting for the copy to show up on the page it may be easier just to refresh the page as you will have to copy a lot of items back and forth. To send the actual copy command you need to send the information required for the copy command to a php script as a get query in the link you request through ajax. eg something like.....


[CODE]
if (window.XMLHttpRequest) { // code for Mozilla, etc.
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=succFunction;
xmlhttp.open("GET","http://localhost/copy.php?table=blah&items=1,2,3,6",true);
xmlhttp.send(null);
} else if (window.ActiveXObject) { // code for IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp) {
xmlhttp.onreadystatechange=succFunction;
xmlhttp.open("GET","http://localhost/copy.php?table=blah&items=1,2,3,6",true);
xmlhttp.send();
}
}

Hope that helps.

Cheers.

Thanx. I resolvet it with javascript

bradgrafelman
01-18-2008, 01:08 PM
Don't forget to mark this thread resolved.