AJAX - The Complete Reference

(avery) #1

48 Part I: Core Ideas


/* add particular the controls */
fileList.appendChild(fileDiv);

/* update our counts */
g_fileList.push(uploadField);
g_fileCount++;
}

function removeAttachFile(fileDiv,uploadField)
{
/* remove item for upload array */
for (var i=0; i < g_fileList.length;i++)
if (g_fileList[i].id == uploadField.id)
g_fileList.splice(i, 1);
/* remove form control */
var fileList = fileDiv.parentNode;
fileList.removeChild(fileDiv);
}
function showStatus()
{
var progressbar = document.getElementById("progressBar");
progressbar.style.display = "";
return true;
}
function showResult()
{
g_fileList = [];
g_fileCount = 1;
document.getElementById("progressBar").style.display="none";
document.getElementById("fileList").innerHTML = "";
document.getElementById("attachButton").value = "Attach File";
}
</script>
</head>
<body>

<div id="uploadControl">
<form enctype="multipart/form-data" action="http://ajaxref.com/ch2/fileupload
.php" method="POST" target="uploadresult" onsubmit="return showStatus();">
<h3>Image Uploader</h3>
<input type="button" id="attachButton" value="Attach File"
onclick="showAttachFile();" />

<div id="fileList"> </div>

<div id="uploadButton">
<input type="submit" value="Upload" />
</div>
</form>
</div>

<br /><br />
Free download pdf