// This adds a new file upload to the form. function AddNewUpload(){ // Get a reference to the upload container. var jFilesContainer = $( "#files" );
// Get the file upload template. var jUploadTemplate = $( "#element-templates div.row" );
// Duplicate the upload template. This will give us a copy // of the templated element, not attached to any DOM. var jUpload = jUploadTemplate.clone();
// At this point, we have an exact copy. This gives us two // problems; on one hand, the values are not correct. On // the other hand, some browsers cannot dynamically rename // form inputs. To get around the FORM input name issue, we // have to strip out the inner HTML and dynamically generate // it with the new values. var strNewHTML = jUpload.html();
// Now, we have the HTML as a string. Let's replace the // template values with the correct ones. To do this, we need // to see how many upload elements we have so far. var intNewFileCount = (jFilesContainer.find( "div.row" ).length + 1);
// Set the proper ID. jUpload.attr( "id", ("file" + intNewFileCount) );
// Replace the values. strNewHTML = strNewHTML .replace( new RegExp( "::FIELD2::", "i" ), intNewFileCount ) .replace( new RegExp( "::FIELD3::", "i" ), ("presoFile" + intNewFileCount) ) ;
// Now that we have the new HTML, we can replace the // HTML of our new upload element. jUpload.html( strNewHTML );
// At this point, we have a totally intialized file upload // node. Let's attach it to the DOM. jFilesContainer.append( jUpload ); }
No, you have not a pure native javascript code, that looks like a framework code. Even a framework is a javascript application, it uses custom methods and functions whom we can not imagine what they suppose to do, unless we know which framework is that. Now, what is that: JQuery? Prototype? Mootools? Another... which one?
Note: You should have not used frameworks for simple tasks like that.
What I really want is:
I have a form that uploads multiple images, I want the form instead to be able to support upto a max of 5 files. And have the files shown like e.g: http://picturedumper.com/pages/index/
(Where when you add more files they will display underneeth eachother) UPTO a max of 5 files
However I was told that this JavaScript Snippet would do the job... Do you have any other code JavaScript or not that would do the above job. I am not experienced within client-side-coding
The problem with javascript is that you need to be experienced with client-side coding in order to create, use, debug codes. You can not simply use a javascript snippet without knowing the language. Things do not work like that in web design/developing. A web designer / developer must know javascript, same as he must know HTML and CSS. These 3 languages are the basis and required.
problem is I know PHP/xHTML and CSS... but these three cannot help me do something client-side that is dynamic!
JavaScript / mootools could...
But of course I can understand the basics when I see the JS code... but I was just asking to tweak the current code to enable a limit... there must be some sort of "count" command like in PHP.. but I cannot figure out how to get that to work in the JS code...
ok. The problem with those frameworks is that you will never know what is hidden behind their custom functions/methods because they are custom. They are not native javascript methods. You may guess or you may start searching for those custom functions/methods in the core of the framework. Which is an intricate job. You could ask people who create that framework. A javascript coder will never be able to help you if he does not know that framework by heart. And usually only the creators are able to.