baconbeastnz Posted June 19, 2009 Share Posted June 19, 2009 Hi there, I am creating (and thought I had finished) a dynamic upload system. Dynamic in that once you have onChanged() all <input type="file"> fields, 2 more pop up, so you can upload as many files as you want. Each time I pop out 2 more fields, I simply regen the fields again with 2 more and set the innerhtml of a div. Doing this removes the values of the already used fields. My plan was to simply maintain the values of the fields by setting the value="" parameter, however this is not possible, due to the security implications!! GRRR I need a way to keep the used fields unchanged so they retain their values, then just pop on 2 extra ones, any ideas? Quote Link to comment Share on other sites More sharing options...
J.Daniels Posted June 19, 2009 Share Posted June 19, 2009 You want to append to the innerHTML element.innerHTML = element.innerHTML + <code to add 2 more input fields>; Quote Link to comment Share on other sites More sharing options...
baconbeastnz Posted June 20, 2009 Author Share Posted June 20, 2009 Yep tried that , doesn't work but JS is still reinstaing the entire HTML for that div. I need something to just add extra html into a div without remaking it all Quote Link to comment Share on other sites More sharing options...
baconbeastnz Posted June 20, 2009 Author Share Posted June 20, 2009 Surely there must be a JS function available to my AJAX object, along the lines of: getelementbyid(element).addHTML = ajaxObj.responseText; Quote Link to comment Share on other sites More sharing options...
corbin Posted June 21, 2009 Share Posted June 21, 2009 The only way I know of to append without replacing content is to use the DOM API. <html> <title>Dynamic Download Fields</title> <script language="javascript"> <!-- function AddSlot(input_element) { var c = input_element.parentNode; if(c != null) { var newFile = document.createElement('input'); var lineBreak = document.createElement('br'); newFile.type="file"; newFile.name="files[]"; newFile.setAttribute('onchange', "AddSlot(this)"); c.appendChild(newFile); c.appendChild(lineBreak); return true; } return false; } //--> </script> </html> <body> <form> <div id="file_container"> <input type="file" name="files[]" onchange="AddSlot(this);"> <br> </div> </form> </body> </html> For example. With AJAX though that's going to get more complex since obviously using a preexisting HTML string complicates things. I think jQuery can append an HTML string without replacement, or you could change how your AJAX is returned. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.