Hey Everyone,
Well what i am trying to do is create a multiple file upload. I have it uploading multiple files just fine. However, now i am trying to add a remove link to each file i upload.
Basically how it works is they choose files to upload an then when they click submit it uploads the files. An now for every file they choose to upload i want it to have a remove button next to it so that if they change there mind they won't have to deal with the problem of having to clear the field themselves (this needs to be done before they click submit). The problem i am having is with the remove part.
Example lets say i decide to upload 3 files an i decide i don't need the second file. The problem i am having is when i go to upload it to my database it still sees the 2nd file there an gives me an error. it will say that there is nothing in the 2nd file when in fact i deleted the 2nd file. But i am wondering how can i make it do this. if i have 3 files f1,f2, f3 how can i instead of it saying f1,f3 (it appears like this if i delete the 2nd file) how can i make it say f1,f2.
i know my explanation is a bit confusing. I have been posting this question in coldfusion part of the forum. but now my question has become more a javascript question then a coldfusion question. But here is a link to that part of the form which might explain what i am trying to do a bit better. http://bytes.com/forum/showthread.ph...88#post3309788
But here is the code i got
javascript - <script type="text/javascript">
-
var upload_number = 1;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput('f"+upload_number+"');");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("totalAttachments").value = upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById(i);
-
document.getElementById("moreUploads").removeChild(elm);
-
upload_number = (upload_number - 1) + 2;
-
}
-
</script>
the html part - <form action="userform.cfm" id="userForm" name="userForm" method="POST" enctype="multipart/form-data">
-
<input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
-
<input type="submit" class="officalsubmit" value="submit" name="submit">
-
</form>
the coldfusion part (action page it goes to once you click submit) - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thanks in advance ,
Rach
Aug 19 '08
68 5302
Hey Acoder
Don't i have the hidden field already going on right now in my form by using totalAttachments?
heres the html with totalAttachments in it. - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
an i believe i am also doing the looping now my action page page. - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
-
the only part i am not understanding is this
then when adding, just add the upload number to this field. When removing, just remove that number from the field
or am i confused an do i have neither?
Thank you :),
Rach
That hidden field is just a simple number. What this new field would have is a list of numbers referring to the numbers in the names of the attachment/description fields, e.g. "1,4,5,6,8" if 2, 3 and 7 were deleted.
Hey Acoder,
alrighty i see what you mean on the difference. But what needs to stay an what needs to go because we have done so much to it i am not sure where to begin.
here is the javascript again. - <script type="text/javascript">
-
var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
<!--- d.appendChild(br);--->
-
d.appendChild(des);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("totalAttachments").value = upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
for (j = i + 1; j < upload_number; j++) {
-
link = document.getElementById("l"+j);
-
div = document.getElementById("f"+j);
-
attachment = document.getElementsByName("attachment"+j)[0];
-
description = document.getElementsByName("description"+j)[0];
-
attachment.setAttribute("name","attachment"+(j - 1));
-
description.setAttribute("name","description"+(j -1));
-
link.setAttribute("id","l"+(j-1));
-
link.setAttribute("href", "javascript:removeFileInput("+(j - 1)+");");
-
div.setAttribute("id","f"+(j-1));
-
}
-
upload_number = upload_number - 1 ;
-
document.getElementById("totalAttachments").value = upload_number - 1;
-
-
}
here is the html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" id="totalAttachments" name="totalAttachments" value="1">
-
<input type="hidden" name="uploads" id="uploads" value="1">
Thank you again for all the help :),
Rach
You don't need the total-attachments field anymore because you can work it out from the new hidden field. In the add function, you only need to change the last line to change the uploads hidden field instead of totalAttachments (instead of adding 1, you need to add a number as a string separated by commas, e.g. - ...value += "," + upload_number;
. In the remove function, you can comment out or get rid of the for loop - the renaming is not needed any more. Again, you need to change the total attachments line to remove the upload number from the list of upload numbers.
Hey Acoder,
alrighty well here is the changes i made. - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
<!--- d.appendChild(br);--->
-
d.appendChild(des);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
upload_number = upload_number - 1 ;
-
document.getElementById("uploads").value = upload_number - 1;
-
-
}
html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" name="uploads" id="uploads" value="1">
the only thing i am concerned about is taking out totalAttachments since it appears in the action page. are you sure taking out totalAttachments won't mess with the action page? here whats on the action page - <cfif structKeyExists(FORM, "totalAttachments")>
-
<cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "uploaded">
-
<cfparam name="FORM.totalAttachments" default="0">
-
<cfloop from="1" to="#form.totalAttachments#" index="counter">
-
<cfset currentDescription = form["description" & counter]>
-
<!---verify the form field exists --->
-
<cfif structKeyExists(FORM, "attachment"& counter)>
-
<!--- try and upload it ...--->
-
<cffile action="upload" fileField="form.attachment#counter#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\" nameconflict="MAKEUNIQUE">
-
<cfset filename = cffile.ClientFileName & "_" & form.id & "_" & counter & "." & cffile.ClientFileExt>
-
<CFFILE ACTION="RENAME" SOURCE="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#CFFILE.ServerFile#" destination="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#filename#">
-
<cfquery name="attachment" datasource="CustomerSupport">
-
exec usp_CS_Insertattachments
-
'#Form.ID#','#evaluate(serialnum)#','#currentDescription#','#filename#','#Form.fk_addedBy#'
-
</cfquery>
-
</cfif>
-
</cfloop>
-
</cfif>
Thank you for the help,
Rach
You'll have to modify the action page too for this to work. Instead of using totalAttachments, use the uploads string value which will be a comma-delimited string to determine which fields contain the upload information. If you can't get that working, post in the original Coldfusion forum thread.
Just one more thing: the remove code isn't quite correct. You need to remove the upload number from the field value using replace() and you don't need to decrease the upload_number any longer.
Hey Acoder,
all definitely post the coldfusion part back in the previous question. because i understand the part about changing the name but the part about the comma-delimited string part has me a bit confused.
but for the remove part do i need to do it like this
what was previously written - function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
upload_number = upload_number - 1 ;
-
document.getElementById("uploads").value = upload_number - 1;
-
-
}
what i changed - {
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
upload_number = upload_number - 1 ;
-
document.getElementById("uploads").value = replace(upload_number);
-
-
}
Thank you,
Rach
Not quite. You don't need to decrease the upload_number. In fact, you shouldn't, so remove that line. replace() is a string method, so you need to use it like this: - document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
Hey Acoder,
Alrighty should this be the whole thing in a nut shell? - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
<!--- d.appendChild(br);--->
-
d.appendChild(des);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
-
-
}
html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" name="uploads" id="uploads" value="1">
the reason i ask is because right now if i click add attachment it wont let me even add another attachment. an i took it to firefox and it said addFileInput is not defined.
Thank you,
Rach
Ah, an elementary mistake: - document.getElementById("uploads").value += "," + upload_number;
Hey Acoder,
Alrighty that works right now (yay). Just got to get the server-side part going which i posted back in coldfusion. But i do got one last question to ask on this. When you click add attachment (to upload multiple files) it puts the word description really close to the file input an i was wondering how would you put some space between the word description and the file input? i been trying to figure it out by myself but i really can't get it. i figured out how to do a break (which you will see is commented out). but i can't figure out how i would just simply space it out. - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
<!--- d.appendChild(br);--->
-
d.appendChild(des);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
Thank you so much for all the help on this :),
Rach
To add space, you can use the non-breaking space character, but it won't work with createTextNode(). For that, you'll need to use the unicode character \u00a0: - var nbsp = document.createTextNode("\u00a0");
then append this.
Hey Acoder,
wow that kills me. I was trying that exact thing an couldn't get it to work!!! i didn't realize you couldn't do it with createTextNode() which now it makes so much since why it didn't work! But THANK YOU SO MUCH for all the help!!! you truely are awesome :) THANK YOU, THANK YOU!!!!
Rach
In case anyone else wants to see the resolution to the javascript an html here it is. - <script type="text/javascript">
-
var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("a");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
var nbsp = document.createTextNode("\u00a0");
-
var space = document.createTextNode("\u00a0");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");
-
l.appendChild(document.createTextNode("Remove"));
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(nbsp);
-
d.appendChild(des);
-
<!--- d.appendChild(br);--->
-
d.appendChild(space);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
-
}
-
</script>
html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" name="uploads" id="uploads" value="1">
OK, I guess that means it worked ;)
I think there's one last thing you had left - to replace the link with a button as shown by Ramanan above.
Acoder,
yeah your right an i been playing with it. But i messed it up :(. i got the button to appear but wont let me remove any. - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("input");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
var nbsp = document.createTextNode("\u00a0");
-
var space = document.createTextNode("\u00a0");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.type="button";
-
l.value="Remove";
-
l.onclick="javascript:removeFileInput("+upload_number+")";
-
<!--- l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");--->
-
<!--- l.appendChild(document.createTextNode("Remove"));--->
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(nbsp);
-
d.appendChild(des);
-
<!--- d.appendChild(br);--->
-
d.appendChild(space);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
Thank you,
Rach
i figured out how to get this to work in internet explorer and firefox!
Thank you again for all the help acoder!
here is the FINAL results to the javascript (html is same as above) - <script type="text/javascript">
-
var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("input");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
var nbsp = document.createTextNode("\u00a0");
-
var space = document.createTextNode("\u00a0");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
l = document.createElement("<input type='button' onclick='javascript:removeFileInput("+upload_number+");'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("type", "button");
-
l.setAttribute("onclick", "javascript:removeFileInput("+upload_number+")");
-
-
l.type="button";
-
l.value="Remove";
-
l.onclick="javascript:removeFileInput("+upload_number+")";
-
<!--- l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");--->
-
<!--- l.appendChild(document.createTextNode("Remove"));--->
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(nbsp);
-
d.appendChild(des);
-
<!--- d.appendChild(br);--->
-
d.appendChild(space);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
-
-
}
-
-
</script>
Try: - l.onclick=function() {removeFileInput(upload_number)};
or you could create a variable function reference and assign that instead.
Edit: Oh, I posted this without realising you'd solved it. Well done.
Try: - l.onclick=function() {removeFileInput(upload_number)};
or you could create a variable function reference and assign that instead.
Edit: Oh, I posted this without realising you'd solved it. Well done.
Hey Acoder,
well i ran into one more problem. if you wouldn't mind solving it.
I tried to send the form without uploading a file an got this error -
Error processing CFFILE
-
-
No data was received in the uploaded file '\' Saving empty (zero-length) files is prohibitted. Please make sure you specified the correct file.
how would i send the form without having a file in it?
heres the javascript - var upload_number = 2;
-
function addFileInput()
-
{
-
var d = document.createElement("div");
-
var l = document.createElement("input");
-
var file = document.createElement("input");
-
var text = document.createElement("input");
-
var nbsp = document.createTextNode("\u00a0");
-
var space = document.createTextNode("\u00a0");
-
<!--- var br = document.createElement("br");--->
-
var des = document.createTextNode("Description")
-
try {
-
file = document.createElement("<input type='file' name='attachment"+upload_number+"'>");
-
text = document.createElement("<input type='text' name='description"+upload_number+"'>");
-
l = document.createElement("<input type='button' onclick='javascript:removeFileInput("+upload_number+");'>");
-
} catch (e) {
-
file = document.createElement("input");
-
text = document.createElement("input");
-
}
-
d.setAttribute("id", "f"+upload_number);
-
file.setAttribute("type", "file");
-
file.setAttribute("name", "attachment"+upload_number);
-
text.setAttribute("type", "text");
-
text.setAttribute("name", "description"+upload_number);
-
l.setAttribute("id", "l"+upload_number);
-
l.setAttribute("type", "button");
-
l.setAttribute("onclick", "javascript:removeFileInput("+upload_number+")");
-
-
l.type="button";
-
l.value="Remove";
-
l.onclick="javascript:removeFileInput("+upload_number+")";
-
<!--- l.setAttribute("href", "javascript:removeFileInput("+upload_number+");");--->
-
<!--- l.appendChild(document.createTextNode("Remove"));--->
-
d.setAttribute("id", "f"+upload_number);
-
d.appendChild(file);
-
d.appendChild(nbsp);
-
d.appendChild(des);
-
<!--- d.appendChild(br);--->
-
d.appendChild(space);
-
d.appendChild(text);
-
d.appendChild(l);
-
document.getElementById("moreUploads").appendChild(d);
-
document.getElementById("uploads").value += "," + upload_number;
-
upload_number++;
-
}
-
-
function removeFileInput(i)
-
{
-
var elm = document.getElementById("f"+i);
-
document.getElementById("moreUploads").removeChild(elm);
-
document.getElementById("uploads").value = document.getElementById("uploads").value.replace(i,"");
-
-
}
heres the html - <input type="file" name="attachment1" id="attachments" value="" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
-
Description <input type="text" name="description1" id="description" value="" />
-
<div id="moreUploads"></div>
-
<div id="moreUploadsLink" style="display:none;">
-
<input type="button" value="Attach another file"
-
onclick="javascript:addFileInput();" >
-
</div>
-
<input type="hidden" name="uploads" id="uploads" value="1">
thank you again for all the help,
Rach
This is actually a Coldfusion problem and the error-checking should be done on the server-side, though you can help the user by checking on the client-side too. This would be achieved by having uploads set to empty to begin with. When you select a file for the first attachment, set it to "1". Just a note that you should never depend on JavaScript error-checking.
For the Coldfusion error-checking, it's back to the other thread.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stan Cook |
last post by:
I was trying to take a list of files in a directory and remove all but the ".dbf" files. I used the following to try to remove the items, but they would not remove. Any help would be greatly...
|
by: wk6pack |
last post by:
Hi,
I'm trying to use the remove method on a string but it doesnt seem to change
it.
name.remove(instr(name," ")-1,1)
If name = bon jovi, I would like bonjovi but I get bon jovi in the...
|
by: Venkat |
last post by:
Hi All,
Currently i guess rename and remove are not supported using fstream.
How do i rename or remove a file?
regards,
Venkat
|
by: Arne Claus |
last post by:
Hi
If've just read, that remove() on a list does not actually remove the
elements, but places them at the end of the list (according to TC++STL
by Josuttis). It also says, that remove returns a...
|
by: tshad |
last post by:
Is there a reason to use session.remove over session.contents.remove?
Don't they both remove the key and data from the contents collection?
I assume that session(x) = nothing does essentially...
|
by: sam_cit |
last post by:
Hi Everyone,
I'm using remove() function to delete a file, and i observed the
following behavior,
Concerned file : sample.txt
Operation : i open the file in read mode and don't close the...
|
by: ken |
last post by:
How to remove specified cookie (via a given name) in cookie jar?
I have the following code, but how can I remove a specified cookie in
the cookie jar?
cj = cookielib.LWPCookieJar()
if cj is...
|
by: =?Utf-8?B?YmJn?= |
last post by:
Hi all,
I wanted to go through each entry(?) of ArrayList and remove some particular
entry. So I tried following but it throws exception at runtime:
foreach (myEntry entry in myArrayList)
{...
|
by: Yansky |
last post by:
Got a quick n00b question. What's the difference between del and
remove?
|
by: Nates |
last post by:
I have a .bas file saved locally that I load into my Acces project to run a particular sub. I use the following code to load the module (which works fine):
I use the following loop to remove...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |