Click to See Complete Forum and Search --> : Sumbit form Access Denied


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.

PeejAvery
June 8th, 2005, 12:36 PM
Wow, I have never heard of click() for JavaScript. In fact, it doesn't even work on my machine. Is this really a subroutine?

cpb123
June 8th, 2005, 12:41 PM
Yeah and it works fine on mine. Any ideas with what my problem may be?

PeejAvery
June 8th, 2005, 12:59 PM
Okay, I was using Firefox browser. Just know that if you want to use this coding in a browser that works with layers instead of document.all, you will not be able to use the click() subroutine.

Post all your script. You talk about a save button but we don't see it or know what it does.

cpb123
June 8th, 2005, 01:12 PM
Ok thank you but it is being developed for IE6. The application is at work so il do my best to explain what it does. The save button runs a function that selects all of the options in the list and then submits the form. The form has an action to a seperate page that is at the moment only writing out the list as a string.

PeejAvery
June 8th, 2005, 01:52 PM
Well, Access Denied means your are writing to something and not just an array of strings.

Isolate that code that is doing some writing and from there you can track down the access management.

I understand why you wouldn't want to post your code but since you don't no one can fully help or understand.

cpb123
June 9th, 2005, 03:58 AM
The reason I din't post my code is that I was at home and the code was at work, as I explained. Here is the 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;
}


Any help would be most grateful

PeejAvery
June 9th, 2005, 10:43 AM
The scripting does not work properly on my machine. I am using Internet Explorer 6.0.2900.2180 patched with SP2. Is there something else I would need to properly execute this page?

What is this "Save" button? Is that the "Submit" button?

cpb123
June 9th, 2005, 11:04 AM
You will need to create a blank page called "UploadedTest.asp" that the page can post to. The images won't work and you need a server to run the pages on that it is able to handle asp files (IIS etc..).

Yes the Save button is the submit button.

PeejAvery
June 9th, 2005, 02:42 PM
I understand the blank asp page, but my machine does not even run your vbscripts.

When I add a file, it does not add to the list. I do not see any options which are to be selected and then recorded. The combobox is only about 10 pixels wide. Should it be like this?

cpb123
June 9th, 2005, 02:53 PM
hmmm not sure whats going on with that. Yes it's only a test page to see if I can get this bit of code working before implementing it into my application.

Drewvy
March 18th, 2008, 07:37 PM
I had the same problem. Make sure you are accessing your webpage via your webserver and not just using the webpage from a local C:\location.

PeejAvery
March 18th, 2008, 07:59 PM
Welcome to the forums Drewvy. Note that this thread is 3 years old. Please make your posts a little more relevant. Thank you.

:wave: