seventheyejosh Posted June 30, 2009 Share Posted June 30, 2009 hello all. I have this here... function more(cur){ var values; for(var i=1;i<cur;i++){ values[i]=document.getElementById('file'+i).value; }//end for if(document.getElementById('file'+cur).value!=''){ cur++; if (document.getElementById('file'+cur)==null){ document.getElementById('holder').innerHTML+='<div class="formcontainer"><div class="formlabel">File '+cur+':</div><div class="forminput"><input type=file name=file'+cur+' id=file'+cur+' onblur="more('+cur+');"></div></div>'; }//end if }//end main var total=values.count(); for (var j=1;j<total;j++){ document.getElementById('file'+j).value=values[j]; }//end for }//end function which with this <div id=holder> <div class="formcontainer"> <div class="formlabel">File 1:</div> <div class="forminput"> <input type=file name=file1 id=file1 value='' onblur="more('1');"> </div> </div> </div> basically when someone chooses a file to upload, when the input is unblurred, if there is a value in the box, i need it to store the value to an array so i can populate it after i make another input thanks Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted June 30, 2009 Share Posted June 30, 2009 so whats the issue isnt the onblur event firing have you tested it with an alert()? http://www.w3schools.com/JS/js_obj_array.asp Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted June 30, 2009 Author Share Posted June 30, 2009 nah the onblur works beautifully. basically it does the innerHTML+= and adds a new input like its supposed to. however, in doing so the inputs lose their values. so i need to build an array of the values, create the new input, and restore the values to the existing ones. im having issues with the arrays. Im so used to php arrays, that they are not working correctly (or as i'd expect) and its killing me. if i do a alert or document.write on the values array it says undefined. same as if i do values.length or values.count(); they arrays are killing me :| Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted June 30, 2009 Author Share Posted June 30, 2009 nevermind, googling reveals that setting the value of a file type input is not allowed for security reasons. so much for that Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted June 30, 2009 Share Posted June 30, 2009 nevermind, googling reveals that setting the value of a file type input is not allowed for security reasons. so much for that thoght so lol maybe you can do somthing with hidden feilds ?? function more(cur){ var values = new array(); for(var i=0;i<cur;i++){ id = i+1; if(document.getElementById('file'+id)){ values[i] = document.getElementById('file'+id).value; alert('file'+id+' Added to array.'); } else{ alert('file'+id+' Does not exist and was not added to the array.'); } } if(document.getElementById('file'+cur).value != ''){ cur++; document.getElementById('holder').innerHTML += '<div class="formcontainer"><div class="formlabel">File '+cur+': </div><div class="forminput"><input type=file name=file'+cur+' id=file'+cur+' onblur="more('+cur+');"></div></div>'; } var total = values.length; for(var i=0;i<cur;i++){ id = i+1; if(document.getElementById('file'+id)){ document.getElementById('file'+id).value = values[i]; alert('file'+id+' Updated.'); } else{ alert('file'+id+' Does not exist and was not updated.'); } } } <div id=holder> <div class="formcontainer"> <div class="formlabel">File 1:</div> <div class="forminput"> <input type=file name=file1 id=file1 value='' onblur="more('1');"> </div> </div> </div> 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.