Submit button needs multiple clicks -
11-09-2007
, 12:03 PM
Hi;
I've just re-written the code used to upload audio tracks to my home server,
as this is all within an intranet, to date I've been using FSO file copy,
but that suspends the browser while the upload takes place.
So I had the bright idea of using a WSH script to do the upload, with the
script being called from the web page. This works great, I now get control
restored immediately and can even upload multiple files at once.
However I now have to click the submit button multiple times before the it
actions, does anybody know why ??
Code fragment below:
Steve
<form name="Form" action="QuickAudio.asp?action=upload" method="POST"
onsubmit="Startupload();">
<table border=0>
<tr>
<td> </td>
<td><h5><div>Selected Files: 0MB</div></h5> If this does not update click
<a href="intranetsecurity.asp">here</a>.</td>
</tr>
<tr>
<td align=right>Album Image File<br/>(Folder.jpg)</td>
<td valign=top><input type="file" dir="rtl" name="Image" size=80
onchange="SizeIt(0);"><img src='annimations\busy2.gif' height=16 width=16
style='visibility:hidden;'></td>
</tr>
<%
For T = 1 to 60
S = FormatNumber(T, 0, 0, 0, 0)
If T < 6 Then
Rline " <tr style='display:inline;'>"
Rline " <td align=right>Track " & S & "</td>"
Rline " <td><input type='file' dir='rtl' name='Track" & S & "' size=80
onchange='SizeIt(" & S & ");' disabled=true><img src='annimations\busy2.gif'
height=16 width=16 style='visibility:hidden;'></td>"
Else
Rline " <tr style='display:none;' >"
Rline " <td align=right>Track " & S & "</td>"
Rline " <td><input type='file' dir='rtl' name='Track" & S & "' size=80
onchange='SizeIt(" & S & ");' disabled=true><img src='annimations\busy2.gif'
height=16 width=16 style='visibility:hidden;'></td>"
End If
Rline " </tr>"
Next
%>
<tr>
<td colspan=2 align=center><input type="hidden" name="Artist"><input
type="submit" name="Submit" value="Upload" disabled=true><input
type="hidden" name="Album"></td>
</tr>
</table>
</form>
<script>
var list = new Array();
var link = new Array();
var size = 0;
var Tracks = 5;
var Last = 4;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(fso.DriveExists("U:")) {
var drv = fso.GetDrive("U:");
if(drv.IsReady) {
if(fso.FolderExists("U:\\Temp")) {
var fld = fso.GetFolder("U:\\Temp");
var fl = new Enumerator(fld.Files);
for (; !fl.atEnd(); fl.moveNext()) {
fl.item().Delete();
}
} else {
var fld = fso.CreateFolder("U:\\Temp");
}
} else {
alert("You are not properly loged on to HomeNet.\nRun
'Start','Programs','Startup','Logon'\n and then try again.");
window.location.href = "QuickAudio.asp";
}
} else {
alert("You are not properly loged on to HomeNet.\nRun
'Start','Programs','Startup','Logon'\n and then try again.");
window.location.href = "QuickAudio.asp";
}
window.setInterval("Monitor();", 1000);
function Monitor() {
var a = document.all.tags("input");
var g = document.all.tags("img");
var i = 0;
while (i < list.length) {
if (fso.FileExists("U:\\Temp\\" + list[i])) {
g[link[i]+12].style.visibility = "hidden";
a[link[i]].disabled = false;
var j = i + 1;
while (j < list.length) {
var n = list[j];
var t = link[j];
list[j] = list[j-1];
link[j] = link[j-1];
list[j-1] = n;
link[j-1] = t;
j++;
}
list.pop();
link.pop();
} else {
i++;
}
}
if (list.length == 0 && size > 0) {
if (Form.Submit.disabled) {
Form.Submit.disabled = false;
}
}
}
function Startupload() {
var pArray = document.Form.Image.value.split("\\");
document.Form.Album.value = pArray[pArray.length - 2];
document.Form.Artist.value = pArray[pArray.length - 3];
return true;
}
function SizeIt(t) {
var a = document.all.tags("input");
var g = document.all.tags("img");
size = 0;
for(var i = 0; i <= Tracks; i++) {
if(a[i].value.length > 0) {
var file = fso.GetFile(a[i].value);
size = size + file.size;
}
}
size /= 1048576;
document.all.tags("div")[0].innerText = "Selected Files: " +
size.toFixed(2) + "MB";
a[t+1].disabled = false;
if (Tracks < 60) {
if (t == Tracks) {
Tshow(t+1);
}
}
if (!Form.Submit.disabled) {
Form.Submit.disabled = true;
}
a[t].disabled = true;
g[t+12].style.visibility = "visible";
var sh = new ActiveXObject("WScript.Shell");
var cmd = "c:\\upload.vbs " + a[t].value;
link.push(t);
list.push(fso.GetFileName(a[t].value));
sh.Run(cmd, 2, true);
}
function Tshow() {
var a = document.all.tags("tr");
if(Tracks < 60) {
Tracks++;
var T = 1 + Tracks;
a[T].style.display = "inline";
}
}
</script> |