cpb123
June 8th, 2005, 11:06 AM
Hi,
I have a page that uses the <Input Type="File"> to browse for a file but I have used the following code to hide the textfield and use an image as the button.
<FORM name="dummy">
<INPUT type="file" class="file" style="display: none" name="hiddenFileName">
<input type="text" style="visibility:hidden" name="Filename">
<input type="button" name="openFile" width=40 height=18 value="open file"
onclick='document.all.hiddenFileName.click(); alert(document.all.hiddenFileName.value)'>
</Form>
The value that is in the hiddenFileName gets appended to my list box. When I click the "Save" button, a VBScript function is run that selects all of the options in the list and then submits the form. The problem is that all the options get selected but the form doesn't submit. An error is fired that says; Error: Access is denied.
HTML Code:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onLoad="MM_preloadImages('../Images/browseOn.gif','../Images/removeOn.gif','../Images/clearFilesOn.gif')">
<form action="UploadedTest.asp" method="post" name="frmDetails" id="frmDetails">
<table>
<tr>
<td class="SectionBreaker" colspan="5"> Enclosures: </td>
</tr>
<tr>
<td colspan="5">
<select name="sbxNom" multiple class="boxDimension">
</select>
</td>
</tr>
<tr>
<td colspan="5">
<p>
<input type="file" class="file" style="display: none" name="hiddenFileName">
<img src="../Images/browse.gif" alt="Add file to the upload list" name="openFile" class="handCursor" onClick='document.all.hiddenFileName.click(); addItem()' onMouseOver="MM_swapImage('openFile','','../Images/browseOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="open file"> <img src="../Images/remove.gif" alt="Remove file(s) from upload list" name="btnRemove" class="handCursor" onClick="removeSelectedOptions(sbxNom);" onMouseOver="MM_swapImage('btnRemove','','../Images/removeOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="Remove File"> <img src="../Images/clearFiles.gif" alt="Clear all files from the upload list" name="btnClear" class="handCursor" onClick="clearList()" onMouseOver="MM_swapImage('btnClear','','../Images/clearFilesOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="Clear List"><br>
<br>
</p></td>
</tr>
</table>
<p>
<input name="Save" type="submit" id="Save" value="Submit">
</p>
</form>
</body>
</html>
<Script language="vbscript">
sub Save_onClick()
For each element in document.frmDetails.sbxNom
element.Selected = True
counter = element.index + 1
Next
//do until document.frmDetails.FileList.value = ""
//Myfilename = left(document.frmDetails.FileList.value,instr(document.frmDetails.FileList.value, vbcrlf))
//document.frmDetails.FileList.value = right(document.frmDetails.FileList.value, len(document.frmDetails.FileList.value)-instr(document.frmDetails.FileList.value, vbcrlf)-1)
//loop
//document.frmDetails.lstfiles.REMOVE(1)
//document.frmDetails.lstfiles.element.add ("We are back (File 2)")
//document.frmDetails.lstfiles.add(1).value = "We're back (File 2)"
document.frmDetails.Submit
end sub
sub clearForm()
if MsgBox("Do you want to clear all the fields in the form?", vbYesNo, "Clear Form")=VBYes Then
document.frmDetails.reset()
end if
end sub
sub printPage()
document.frmDetails.hiddenPrint.value = true
document.frmDetails.submit()
end sub
sub uploadFiles()
document.frmDetails.submit()
end sub
</script>
<Script language="javascript">
function addItem(){
var s = document.forms['frmDetails']['sbxNom'];
s.options[s.options.length] = new Option(document.frmDetails.hiddenFileName.value,document.frmDetails.hiddenFileName.value,false); /* true would select it */
}
function clearList(){
document.forms['frmDetails'].sbxNom.options.length = 0;
}
function removeSelectedOptions(obj){
var SomethingSelected = false;
if (!hasOptions(obj)) {
return;
}
for (var i=(obj.options.length-1); i>=0; i--) {
var o=obj.options[i];
if (o.selected) {
SomethingSelected = true;
obj.options[i] = null;
}
}
if (SomethingSelected == false) {
alert("Please select a file to remove.");
}
obj.selectedIndex = -1;
}
function hasOptions(obj) {
if (obj!=null && obj.options!=null) {
return true;
}
return false;
}
I have set all permissions on folders and through IIS to everyone having full control. If I click on the save button the page submits fine. Also if i click the save button again once the Access is denied error appears it submits but has lost the information from the previous page. Please can someone explain to me what is going on? and what can be done to rectify the problem.
Thank you in advance.
I have a page that uses the <Input Type="File"> to browse for a file but I have used the following code to hide the textfield and use an image as the button.
<FORM name="dummy">
<INPUT type="file" class="file" style="display: none" name="hiddenFileName">
<input type="text" style="visibility:hidden" name="Filename">
<input type="button" name="openFile" width=40 height=18 value="open file"
onclick='document.all.hiddenFileName.click(); alert(document.all.hiddenFileName.value)'>
</Form>
The value that is in the hiddenFileName gets appended to my list box. When I click the "Save" button, a VBScript function is run that selects all of the options in the list and then submits the form. The problem is that all the options get selected but the form doesn't submit. An error is fired that says; Error: Access is denied.
HTML Code:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onLoad="MM_preloadImages('../Images/browseOn.gif','../Images/removeOn.gif','../Images/clearFilesOn.gif')">
<form action="UploadedTest.asp" method="post" name="frmDetails" id="frmDetails">
<table>
<tr>
<td class="SectionBreaker" colspan="5"> Enclosures: </td>
</tr>
<tr>
<td colspan="5">
<select name="sbxNom" multiple class="boxDimension">
</select>
</td>
</tr>
<tr>
<td colspan="5">
<p>
<input type="file" class="file" style="display: none" name="hiddenFileName">
<img src="../Images/browse.gif" alt="Add file to the upload list" name="openFile" class="handCursor" onClick='document.all.hiddenFileName.click(); addItem()' onMouseOver="MM_swapImage('openFile','','../Images/browseOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="open file"> <img src="../Images/remove.gif" alt="Remove file(s) from upload list" name="btnRemove" class="handCursor" onClick="removeSelectedOptions(sbxNom);" onMouseOver="MM_swapImage('btnRemove','','../Images/removeOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="Remove File"> <img src="../Images/clearFiles.gif" alt="Clear all files from the upload list" name="btnClear" class="handCursor" onClick="clearList()" onMouseOver="MM_swapImage('btnClear','','../Images/clearFilesOn.gif',1)" onMouseOut="MM_swapImgRestore()" type="image" value="Clear List"><br>
<br>
</p></td>
</tr>
</table>
<p>
<input name="Save" type="submit" id="Save" value="Submit">
</p>
</form>
</body>
</html>
<Script language="vbscript">
sub Save_onClick()
For each element in document.frmDetails.sbxNom
element.Selected = True
counter = element.index + 1
Next
//do until document.frmDetails.FileList.value = ""
//Myfilename = left(document.frmDetails.FileList.value,instr(document.frmDetails.FileList.value, vbcrlf))
//document.frmDetails.FileList.value = right(document.frmDetails.FileList.value, len(document.frmDetails.FileList.value)-instr(document.frmDetails.FileList.value, vbcrlf)-1)
//loop
//document.frmDetails.lstfiles.REMOVE(1)
//document.frmDetails.lstfiles.element.add ("We are back (File 2)")
//document.frmDetails.lstfiles.add(1).value = "We're back (File 2)"
document.frmDetails.Submit
end sub
sub clearForm()
if MsgBox("Do you want to clear all the fields in the form?", vbYesNo, "Clear Form")=VBYes Then
document.frmDetails.reset()
end if
end sub
sub printPage()
document.frmDetails.hiddenPrint.value = true
document.frmDetails.submit()
end sub
sub uploadFiles()
document.frmDetails.submit()
end sub
</script>
<Script language="javascript">
function addItem(){
var s = document.forms['frmDetails']['sbxNom'];
s.options[s.options.length] = new Option(document.frmDetails.hiddenFileName.value,document.frmDetails.hiddenFileName.value,false); /* true would select it */
}
function clearList(){
document.forms['frmDetails'].sbxNom.options.length = 0;
}
function removeSelectedOptions(obj){
var SomethingSelected = false;
if (!hasOptions(obj)) {
return;
}
for (var i=(obj.options.length-1); i>=0; i--) {
var o=obj.options[i];
if (o.selected) {
SomethingSelected = true;
obj.options[i] = null;
}
}
if (SomethingSelected == false) {
alert("Please select a file to remove.");
}
obj.selectedIndex = -1;
}
function hasOptions(obj) {
if (obj!=null && obj.options!=null) {
return true;
}
return false;
}
I have set all permissions on folders and through IIS to everyone having full control. If I click on the save button the page submits fine. Also if i click the save button again once the Access is denied error appears it submits but has lost the information from the previous page. Please can someone explain to me what is going on? and what can be done to rectify the problem.
Thank you in advance.