Jump to content

[SOLVED] Javascript Arrays...


seventheyejosh

Recommended Posts

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 :)

Link to comment
Share on other sites

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 :|

Link to comment
Share on other sites

nevermind, googling reveals that setting the value of a file type input is not allowed for security reasons.

 

so much for that :D

 

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.