<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
//alert(http_request.status);
if (http_request.status == 200) {
result = http_request.responseText;
//document.getElementById('myspan').innerHTML = result;
//if(result=="Save OK!") http_request = true;
alert(result);
//printData();
} else {
alert('There was a problem with the request.');
}
}
}
function get(obj) {
var getstr = "?";
var elems=obj.elements;
//var elems=obj.childNodes;
for (i=0; i<elems.length; i++) {
if (elems[i].tagName == "INPUT") {
if (elems[i].type == "text") {
getstr += elems[i].name + "=" + escape(elems[i].value) + "&";
}
if (elems[i].type == "hidden") {
getstr += elems[i].name + "=" + elems[i].value + "&";
}
if (elems[i].type == "password") {
getstr += elems[i].name + "=" + elems[i].value + "&";
}
if (elems[i].type == "checkbox") {
if (document.getElementsByName(elems[i].name).length>1) {
var arry = new Array();
for(x=0; x<document.getElementsByName(elems[i].name).length; x++) {
if (document.getElementsByName(elems[i].name)[x].checked) {
arry.push(document.getElementsByName(elems[i].name)[x].value);
}
//i++;
}
//i = i - 1;
getstr += elems[i].name + "=" + arry + "&";
i = i + document.getElementsByName(elems[i].name).length-1;
}
else {
if (elems[i].checked) {
getstr += elems[i].name + "=" + elems[i].value + "&";
} else {
getstr += elems[i].name + "=&";
}
}
}
if (elems[i].type == "radio") {
if (elems[i].checked) {
getstr += elems[i].name + "=" + elems[i].value + "&";
}
}
}
if (elems[i].tagName == "SELECT") {
var sel = elems[i];
getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
}
if (elems[i].tagName == "TEXTAREA") {
var repstr = escape(elems[i].value);
repstr = repstr.replace('\n','<br>');
getstr += elems[i].name + "=" + escape(elems[i].value) + "&";
}
}
if(!http_request)
makeRequest('save.php', getstr);
else
alert("Already Saved!");
}
</SCRIPT>
<form action="" onSubmit="get(this);" ENCTYPE="multipart/form-data">
<input type=checkbox name=array_var[] value=1>1
<input type=checkbox name=array_var[] value=2>2
<input type=checkbox name=array_var[] value=3>3
.....
</form>
---- save.php ----
$array_var_count=count($array_var);
for($i=0;$i<$array_var_count;$i++){
$array_var_val.=$_POST[array_var][$i];
if($i<$array_var_count-1){
$array_var_val.=',';
}
}
if (!$array_var_val) $array_var_val = $array_var[0];
echo "Save OK!"