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
https://forums.phpfreaks.com/topic/164262-solved-javascript-arrays/
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 :|

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.