JavaScript - Custom File Upload?
I'm hoping someone can help me out on this. I know that the input "file" type can't be customized very well using css, so I figured I might try to make my own with javascript. The only problem is, I don't know too much about javascript. So can someone please point me in the right direction on how to make my own custom file upload box in javascript that works the same way as the default one works (so I don't have to edit my PHP coding). Thank you so much!
Also, heres something I'd like to achieve: The box I'd like to create is at the top, while the default one is at the bottom. Similar TutorialsHello every one never really used a board for something like this but my java is a little limited so i need some help here if possible! I have a page with 5 file inputs and 5 img tags i have everything working but preview of course changes all the img tags so no madder what browse button i choose all fixed img tags are updated with that preview. here is a code i found and messed with a little cant seem to figure out how to add a loop or something to update just the called tag if any one could help Java Script: <script type="text/javascript"> <!-- Begin /***** CUSTOMIZE THESE VARIABLES *****/ // width to resize large images to var maxWidth=115; // height to resize large images to var maxHeight=115; // valid file types var fileTypes=["bmp","gif","png","jpg","jpeg"]; // the id of the preview image tag var outImage="previewField"; // what to display when the image is not valid var defaultPic="/images/evolve/badpic.jpg"; /***** DO NOT EDIT BELOW *****/ function preview(what){ var source=what.value; var ext=source.substring(source.lastIndexOf(".")+1,sou rce.length).toLowerCase(); for (var i=0; i<fileTypes.length; i++){ if (fileTypes[i]==ext){ break; } } globalPic=new Image(); if (i<fileTypes.length){ //FireFox try{ globalPic.src=what.files[0].getAsDataURL(); }catch(err){ globalPic.src=source; } }else { globalPic.src=defaultPic; alert(fileTypes.join(", ")); } setTimeout("applyChanges()",200); } var globalPic; function applyChanges(){ var field=document.getElementById(outImage); var x=parseInt(globalPic.width); var y=parseInt(globalPic.height); if (x>maxWidth) { y*=maxWidth/x; x=maxWidth; } if (y>maxHeight) { x*=maxHeight/y; y=maxHeight; } field.style.display=(x<1 || y<1)?"none":""; field.src=globalPic.src; field.width=x; field.height=y; } // End --> previewField is the key i think and also of course the imageout jsut dont know how to go about making the loop if this was perl no problem but like stated above i know little about java coding but minor changes. below here is the some of the form code: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td scope="col"> <img alt="Graphic will preview here" id="previewField" src="/images/evolve/addpic.jpg" width="115" height="115"><br /> <label class="cabinet"><input type="file" name="images[]" id="picField" onchange="preview(this)" class="file"></label> </td> <td scope="col"> <img alt="Graphic will preview here" id="previewField" src="/images/evolve/addpic.jpg" width="115" height="115"><br /> <label class="cabinet"><input type="file" name="images[]" id="picField" onchange="preview(this)" class="file"></label> </td> <td scope="col"> <img alt="Graphic will preview here" id="previewField" src="/images/evolve/addpic.jpg" width="115" height="115"><br /> <label class="cabinet"><input type="file" name="images[]" id="picField" onchange="preview(this)" class="file"></label> </td> <td scope="col"> <img alt="Graphic will preview here" id="previewField" src="/images/evolve/addpic.jpg" width="115" height="115"><br /> <label class="cabinet"><input type="file" name="images[]" id="picField" onchange="preview(this)" class="file"></label> </td> <td scope="col"> <img alt="Graphic will preview here" id="previewField" src="/images/evolve/addpic.jpg" width="115" height="115"><br /> <label class="cabinet"><input type="file" name="images[]" id="picField" onchange="preview(this)" class="file"></label> </td> </tr> </table> also ther is one include: <script type="text/javascript" src="/java/si.files.js"></script> i went through this code file and the change does not appear to be where the change should ocur im sure its in the actually script need to loop through the images[] field i would think like i would in php The only thing i could think to do is paste the script code 5 more times and change each variable to 1 2 3 4 5 but then ill have a big php code page there would be a way to make this work i would think Thanks all and im here for PHP or Perl questions so any help would be great! If there is a better approach any input would be great! hi i m creating a webpage using javascript and php where i need to upload a doc file or zip and read all the words in doc file if it is zip i need to read all the words in all the doc files. i m trying to upload using file input but it does not show path of file only file name how i m suppose to upload and read it. Hi there, I have a File Upload tool and would like to prevent the users from clicking on the textbox to upload files. Also, I want to disallow the manual entering of file pathname. How should I edit it? I would need to use Javascript. <input type="file" name="attachment" id="attachment" style="width:300px" /> Hi there, I would like to know how I can show the line "Attach another File" right away, instead of what is depicted in my own code of showing it after a file has been attached. Also, I would like to align "Attach another File" to the right, so that the word "file" will be below the Browse button. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> var upload_number; function addFileInput() { var d = document.createElement("div"); var file = document.createElement("input"); file.setAttribute("type", "file"); file.setAttribute("name", "attachment"+upload_number); d.appendChild(file); document.getElementById("moreUploads").appendChild(d); upload_number++; } </script> </head> <body> <input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" /> <div id="moreUploads"></div> <div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();">Attach another File</a></div> </body> </html> I'm attempting to pull the hidden iframe file upload trick using javascript. I've go my form file upload and iframe fine, but I can't figure out what to do when it gets server side. There seems to be relatively no documentation on how to handle uploaded files in server-side javascript. Ideas? I'm at a loss.
Hi everybody, I have this File Upload control, whereby the user is granted a limit of 5 uploads. And so, the user clicks on "Attach Another File", and decides to attach a file ONLY in the first File Upload control. My problem is, I want the user to be able to click on an "X" beside every File Upload control, so that it will close those unnecessary (or unused) FIle Upload controls. How do I edit my code in JAVASCRIPT? Please advise. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script language="javascript" type="text/javascript"> var fileCount = 1; function addOneFile() { ++fileCount; var div = document.getElementById("showFile"+fileCount); if ( div != null ) div.style.display = "block"; } </script> <style type ="text/css"> .style37 { color: Black; margin-left: 99px; } </style> </head> <body> <table cellpadding="5"> <tr> <td style="vertical-align: top"> Attachment: </td> <td> <input type="file" name="attachment" id="attachment" style="width:230px" /> <div id="showFile2" style="display: none;"> <input name="file2" type="file" /> </div> <div id="showFile3" style="display: none;"> <input name="file3" type="file" /> </div> <div id="showFile4" style="display: none;"> <input name="file4" type="file" /> </div> <div id="showFile5" style="display: none;"> <input name="file5" type="file" /> </div> <br /> <a href="javascript:addOneFile();" class="style37">Attach another File</a> <br /> (Restricted to 5 uploads) </td> </tr> </table> </body> </html> i have a html/php form which let users upload pictures onto my server. the problem with it is, it says the picture has been uploaded but if the file name contains any of character apart from text (A-z) and numbers, the picture never shows up in the admin panel. is there a way using ajax or jquery to disallow certain file names in the upload field of the html which uses these characters !@#$%^'&*()"? how do i go on about this? hi, i am using <input type = "file" id = "upload"> in my html page. i want to disable the textbox of this control so that user cannot type any file location here. user can upload file only through browse button. is there a way to disable this textbox thru javascript? thnx Hey there everyone I'm a bit new to javascript and having a bit of a problem. I have a page users can click to upload a photo. When users click I want a modal window to pop up with a simple file upload input inside it and a submit button. I have this working except that when users click submit nothing happens. I'm using nyroModal http://nyromodal.nyrodev.com/#demos and the code I use is: Code: <a href="#test" class="nyroModal"><img src="/img/uploadimage.gif" alt="" /></a> <div id="test" style="display: none; width: 600px;"> <form id="ImageUploadForm" enctype="multipart/form-data" method="post" action="images/upload" accept-charset="utf-8"> <div style="display:none;"> <input type="hidden" name="_method" value="POST" /> </div> <div class="input file"> <label for="ImageFileName">File Name</label> <input type="file" name="data[Image][fileName]" id="ImageFileName" /> </div> <div class="submit"><input type="submit" value="Upload" /> </div> </form> </div> If I take the code out of the div=id"test" the form appears on the normal page and submits just fine. Inside the test div tho the modal window pops up with the form inside but the submit button does nothing. Can anyone enlighten me what I'm doing wrong? I am trying for a javascript code that would ask for the excel file location when run, fetch data from two columns till eof in an excel file (MS Excel 2010), append it to an existing text file and upload the plain text file to an ftp location. The ftp username, password and location needs to be hard coded in the script. Is this possible? I am looking for a custom pop up box, but there is only 3 kinds (Alert, Confirm, Prompt). Neither of those will work. This is what I want to do. http://www.youtube.com/watch?v=zr0F6elv-vg I already have a sort function that but wish to provide my users with the ability to specify custom sorts - days of the week, months etc. Assuming that I have a function that will return day of week (ie 'Mon' = 0, "Tue" = 1, "Wed" = 2 ... etc) can anyone show me how I would incorporate this into a sort routine? Many thanks in advance should you respond to this. Hey guys, I'm trying to call the following custom tag: <mvt:item name="category_tree" /> from a JS function: <script language="javascript" type="text/javascript"> <!-- function left_nav_bar () { document.write('Categories:'); document.write('<mvt:item name="category_tree" />'); } //--> </script> But the custom tag is not executing in the browser. Am I calling it wrong from my JS code? I'm trying to create a custom drop down and using the code below it works pretty well - only one problem is if i have more than one drop down, all the links will only activate the first drop down. Any ideas on how I would fix that? Code: function toggle() { var ele = document.getElementById("dropdown-items"); var text = document.getElementById("dropdown-menu"); if(ele.style.display == "block") { ele.style.display = "none"; } else { ele.style.display = "block"; } } I have a successful translator that has random letter, number and symbols assigned to various letters problem is it only lets assign 1 character to 1 letter when i want to assign 4 characters to each letter to ensure the code cant be broken here is a snipet of what im working with its different then normal translators....
Code: <script language="javascript"> function translate() { if (document.form1.elements[0].checked == true) { EtoA() } else if (document.form1.elements[1].checked == true) { AtoE() } else { } } function EtoA() { var toggle = "false" var xlate = document.form1.elements[4].value var xlation = "" document.form1.elements[5].value = "" for (var i = 0; i <= xlate.length; i++) { tempa = xlate.charAt(i) if ( tempa == "[") { toggle = "true" i++ } else if ( tempa == "]") { toggle = "false" i++ } tempa = xlate.charAt(i) if (toggle == "true") { tempb = tempa } else if(tempa == "a") { tempb = "9" } else if(tempa == "b") { tempb = "a" } else if(tempa == "c") { tempb = "0" } else if(tempa == "d") { tempb = "c" } else if(tempa == "e") { tempb = "3" } else if(tempa == "f") { tempb = "b" } else if(tempa == "g") { tempb = "4" } else if(tempa == "h") { tempb = "?" } else if(tempa == "i") { tempb = "5" } else if(tempa == "j") { tempb = "6" } else if(tempa == "k") { tempb = "e" } else if(tempa == "l") { tempb = "+" } else if(tempa == "m") { tempb = "x" } else if(tempa == "n") { tempb = "7" } else if(tempa == "o") { tempb = "v" } else if(tempa == "p") { tempb = "1" } else if(tempa == "q") { tempb = "t" } else if(tempa == "r") { tempb = "q" } else if(tempa == "s") { tempb = "g" } else if(tempa == "t") { tempb = "n" } else if(tempa == "u") { tempb = "<" } else if(tempa == "v") { tempb = ">" } else if(tempa == "w") { tempb = "^" } else if(tempa == "x") { tempb = "!" } else if(tempa == "y") { tempb = "@" } else if(tempa == "z") { tempb = "#" } else if(tempa == "A") { tempb = "9" } else if(tempa == "B") { tempb = "a" } else if(tempa == "C") { tempb = "0" } else if(tempa == "D") { tempb = "c" } else if(tempa == "E") { tempb = "3" } else if(tempa == "F") { tempb = "b" } else if(tempa == "G") { tempb = "4" } else if(tempa == "H") { tempb = "h" } else if(tempa == "I") { tempb = "5" } else if(tempa == "J") { tempb = "6" } else if(tempa == "K") { tempb = "e" } else if(tempa == "L") { tempb = "f" } else if(tempa == "M") { tempb = "x" } else if(tempa == "N") { tempb = "7" } else if(tempa == "O") { tempb = "v" } else if(tempa == "P") { tempb = "1" } else if(tempa == "Q") { tempb = "t" } else if(tempa == "R") { tempb = "q" } else if(tempa == "S") { tempb = "g" } else if(tempa == "T") { tempb = "n" } else if(tempa == "U") { tempb = "<" } else if(tempa == "V") { tempb = ">" } else if(tempa == "W") { tempb = "^" } else if(tempa == "X") { tempb = "!" } else if(tempa == "Y") { tempb = "@" } else if(tempa == "Z") { tempb = "#" } else if(tempa == "1") { tempb = "}" } else if(tempa == "2") { tempb = "{" } else if(tempa == "3") { tempb = "(" } else if(tempa == "4") { tempb = "'" } else if(tempa == "5") { tempb = "|" } else if(tempa == "6") { tempb = "`" } else if(tempa == "7") { tempb = ":" } else if(tempa == "8") { tempb = ";" } else if(tempa == "9") { tempb = "=" } else if(tempa == "0") { tempb = ")" } else if(tempa == "~") { tempb = "R" } else if(tempa == "!") { tempb = "T" } else if(tempa == "@") { tempb = "F" } else if(tempa == "#") { tempb = "Y" } else if(tempa == "$") { tempb = "K" } else if(tempa == "%") { tempb = "J" } else if(tempa == "^") { tempb = "H" } else if(tempa == "&") { tempb = "G" } else if(tempa == "*") { tempb = "X" } else if(tempa == "_") { tempb = "V" } else if(tempa == "-") { tempb = "B" } else if(tempa == "+") { tempb = "M" } else if(tempa == "=") { } else if(tempa == "<") { tempb = "N" } else if(tempa == ">") { tempb = "U" } else if(tempa == ".") { tempb = "S" } else if(tempa == ",") { tempb = "W" } else if(tempa == "?") { tempb = "." } else if(tempa == ":") { tempb = "," } else if(tempa == ";") { tempb = "$" } else { tempb = tempa } xlation = document.form1.elements[5].value document.form1.elements[5].value = xlation + tempb } } function AtoE() { var toggle = "false" var xlate = document.form1.elements[4].value var xlation = "" document.form1.elements[5].value = "" for (var i = 0; i <= xlate.length; i++) { tempa = xlate.charAt(i) if ( tempa == "[") { toggle = "true" i++ } else if ( tempa == "]") { toggle = "false" i++ } tempa = xlate.charAt(i) if (toggle == "true") { tempb = tempa } else if(tempa == "9") { tempb = "a" } else if(tempa == "a") { tempb = "b" } else if(tempa == "0") { tempb = "c" } else if(tempa == "c") { tempb = "d" } else if(tempa == "3") { tempb = "e" } else if(tempa == "b") { tempb = "f" } else if(tempa == "4") { tempb = "g" } else if(tempa == "?") { tempb = "h" } else if(tempa == "5") { tempb = "i" } else if(tempa == "6") { tempb = "j" } else if(tempa == "e") { tempb = "k" } else if(tempa == "+") { tempb = "l" } else if(tempa == "x") { tempb = "m" } else if(tempa == "7") { tempb = "n" } else if(tempa == "v") { tempb = "o" } else if(tempa == "1") { tempb = "p" } else if(tempa == "t") { tempb = "q" } else if(tempa == "q") { tempb = "r" } else if(tempa == "g") { tempb = "s" } else if(tempa == "n") { tempb = "t" } else if(tempa == "<") { tempb = "u" } else if(tempa == ">") { tempb = "v" } else if(tempa == "^") { tempb = "w" } else if(tempa == "!") { tempb = "x" } else if(tempa == "@") { tempb = "y" } else if(tempa == "#") { tempb = "z" } else if(tempa == "9") { tempb = "A" } else if(tempa == "a") { tempb = "B" } else if(tempa == "0") { tempb = "C" } else if(tempa == "c") { tempb = "D" } else if(tempa == "3") { tempb = "E" } else if(tempa == "b") { tempb = "F" } else if(tempa == "4") { tempb = "G" } else if(tempa == "?") { tempb = "H" } else if(tempa == "5") { tempb = "I" } else if(tempa == "6") { tempb = "J" } else if(tempa == "e") { tempb = "K" } else if(tempa == "+") { tempb = "L" } else if(tempa == "x") { tempb = "M" } else if(tempa == "7") { tempb = "N" } else if(tempa == "v") { tempb = "O" } else if(tempa == "1") { tempb = "P" } else if(tempa == "t") { tempb = "Q" } else if(tempa == "q") { tempb = "R" } else if(tempa == "g") { tempb = "S" } else if(tempa == "n") { tempb = "T" } else if(tempa == "<") { tempb = "U" } else if(tempa == ">") { tempb = "V" } else if(tempa == "^") { tempb = "W" } else if(tempa == "!") { tempb = "X" } else if(tempa == "@") { tempb = "Y" } else if(tempa == "#") { tempb = "Z" } else if(tempa == "}") { tempb = "1" } else if(tempa == "{") { tempb = "2" } else if(tempa == "(") { tempb = "3" } else if(tempa == "'") { tempb = "4" } else if(tempa == "|") { tempb = "5" } else if(tempa == "`") { tempb = "6" } else if(tempa == ":") { tempb = "7" } else if(tempa == ";") { tempb = "8" } else if(tempa == "=") { tempb = "9" } else if(tempa == ")") { tempb = "0" } else if(tempa == "R") { tempb = "~" } else if(tempa == "T") { tempb = "!" } else if(tempa == "F") { tempb = "@" } else if(tempa == "Y") { tempb = "#" } else if(tempa == "K") { tempb = "$" } else if(tempa == "J") { tempb = "%" } else if(tempa == "H") { tempb = "^" } else if(tempa == "G") { tempb = "&" } else if(tempa == "X") { tempb = "*" } else if(tempa == "V") { tempb = "_" } else if(tempa == "B") { tempb = "-" } else if(tempa == "M") { tempb = "+" } else if(tempa == "N") { tempb = "<" } else if(tempa == "U") { tempb = ">" } else if(tempa == "S") { tempb = "." } else if(tempa == "W") { tempb = "," } else if(tempa == ".") { tempb = "?" } else if(tempa == ",") { tempb = ":" } else if(tempa == "$") { tempb = ";" } else { tempb = tempa } xlation = document.form1.elements[5].value document.form1.elements[5].value = xlation + tempb } } Can anyone help me out in assigning more then one character? Multple characters work when going english to my custom assignments but it cant translate back from my custom assignments to english. Currently we have an implementation of Lightbox (not sure which version) on our site that aids in the process of a voting system. I wasn't around when it was created, and after creating a new version of the site, have no idea how to re-integrate it so I was hoping some seasoned JS people out there can help me. Now what happens is that people go to the voting page where the list is populated with entries from a mysql db. The names are clickable and, when clicked, a lightbox should show up with the information about the person and have a vote and close button. The vote button, when pressed, should tick a single vote back in the mysql db, and then take them to a "Thank you for voting, here are the current top 10" type page. That's the overall function. Here's what information I do have so far: In the root directory there's a folder named templates Inside of that, there's a folder called Lightbox inside of Lightbox, there are 3 folders [css, images, and js] The *.js folder has [builder.js, effects.js, lightbox.js, prototype.js and scriptaculous.js] inside When clicking on a name, however, it just takes me to the image as if it's directly linked instead of opening up the Lightbox. So I need some help getting this to work. Hi all, The question is hopefully relatively simple. if I have an object say Code: [ var SampleObject = function(id){ SampleObject.id = id; SampleObject.age= 22; } Is there a way to create an event that triggers every time the age member value changes? Thanks Ollie. Hi there I'm trying to use custom events in jQuery to emulate a keyup event. Basically the main keyup event would trigger multiple custom events that emulate keyup events. That way I can bind and unbind these events to/from the DOM without unbinding other events that may be attached to the main keyup event. Here's a non-working example, any explanation as to why this doesn't work would be greatly appreciated! Ps. I think the problem is because the keyCode from the keyup event is not passed to the the trigger, but I don't know how to make that work. Code: var flag = 0; $(document).bind("keyup", function(e) { if(flag) { $(this).trigger("customkeyup1"); } else { $(this).trigger("customkeyup2"); } }).bind("customkeyup1", function(e) { if(e.keyCode == 13){ alert('customkeyup1'); $(document).unbind("customkeyup1"); } }).bind("customkeyup2", function(e) { if(e.keyCode == 13){ alert('customkeyup2'); } }); $("#foo").click(function() { flag = flag == 1 ? 0 : 1; }); Hello, I am trying to make a custom select menu. Here is what I have so far: http://mikewgd.com/wp-content/portfo...custom-select/ Im just stuck at getting the <li> to become selected and etc... I am using this as reference: http://v2.easy-designs.net/articles/replaceSelect/ -- Im not using there script exactly Im doing it a different way. Im doing it more as a dropdown menu Code: <ul class="select"> <li class="selected"> cheese <ul class="drop"> <li>milk</li> <li>bread</li> <li class="selected">cheese</li> <li>pickles</li> <li>salsa</li> </ul> </li> </ul> |