Current location: Hot Scripts Forums » General Web Coding » JavaScript » Send file names to parent window hidden input fields


Send file names to parent window hidden input fields

Reply
  #1 (permalink)  
Old 09-27-06, 06:19 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Send file names to parent window hidden input fields

I have the following JS functions:

Code:
function GetDisplayName(path)
{
  var i;
  if (
  (i = path.lastIndexOf("\\")) != -1 
	  || 
  (i = path.lastIndexOf("/")) != -1
   ) {
   return i < path.length ? path.substring(i + 1) : "";
   }
   return path;
   }
Code:
function BeginAttach()
{  	 
	var path = document.filesform.userFile.value;
  	var displayName = GetDisplayName(path);
  	
	self.opener.document.foo.attach1.value = displayName;
  	self.opener.document.foo.submit();
  	self.close();
}
the parent page has 10 hidden input field, something like:

Code:
<input type="hidden" name="attach1" value="">
<input type="hidden" name="attach2" value="">
etc..
In child window I have 10 file input field :

Code:
<input type="file" name="userFile[]" size="20">
<input type="file" name="userFile[]" size="20">
etc..
I don't really know what I need to do to send the file name of each "file" field to parent page.

Code:
self.opener.document.foo.attach1.value = 'FileName1';
self.opener.document.foo.attach1.value = 'FileName2';
Any idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 06:36 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I explain exactly what I need.

I need to put this values:

Code:
<input type="file" name="userFile[]" size="20">
<input type="file" name="userFile[]" size="20">
to:

Code:
self.opener.document.foo.attach1.value = Value from first "file" field;
self.opener.document.foo.attach2.value = Value from second "file" field;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-27-06, 06:46 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
try a for loop to loop over the entries:
Code:
for( var i=0; i<number_of_entries; i++){
  window.opener.document.foo.attach{i}.value = document.filesform.userFile[i].value;
}
i'm not sure about the {} but if you search the web, i'm sure you'll find how to do so

Hope this helps,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-27-06, 06:50 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
yes I get this error:

Error: window.opener.document.foo.attach has no properties
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-27-06, 06:54 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
you can place all the attach fields in an array:
Code:
attach = new array(number_of_fields);
attach[0] = "window.opener.document.foo.attach1.value";
attach[1] = "window.opener.document.foo.attach2.value";
attach[2] = "etc";
for(var i=0; i<number_of_fields; i++){
  eval(attach[i]+" = "+document..filesform.userFile[i].value);
}
don't know if there's an eval function in javascript, but i think there is. Try this and post back,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-27-06, 07:02 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, I receive this error

Code:
Error: XML descendants internal method called on incompatible HTMLDocument
with following JS code:

Code:
  	attach = new Array();
  	attach[0] = "window.opener.document.foo.attach1.value";
	attach[1] = "window.opener.document.foo.attach2.value";
	
 	for(var i=0; i<3; i++)
 	{
  		eval(attach[i]+" = "+document..filesform.userFile[i].value);
	}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-27-06, 07:11 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
try removing that dot:
not:
Code:
document..filesform.userFile[i].value);
but:
Code:
document.filesform.userFile[i].value);
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-27-06, 07:13 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
hmm, strange.Now I get this message:

Code:
Error: document.filesform.userFile has no properties
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-27-06, 07:23 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
why are you naming all the inputs the same? you could just give them all a different name, this makes it a little easier. that way you can place them in an array and then loop over them, just as you do with the attach fields.

i have no idea why this is giving errors. you could try this, but i don't know if it's gonna work:
Code:
document.filesform.eval(userFile[i]).value
Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 09-27-06, 07:27 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
why are you naming all the inputs the same?
Because I use the same name with foreach (PHP).

Ok I try to find an answer on google. Thanks anyway
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
send data back to parent window zoliky JavaScript 10 09-25-06 06:46 AM
how do I update form, and hidden values in a form from a popup window? lordmerlin JavaScript 2 12-13-05 03:05 PM
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Enter information into fields, creates XML file on the fly ziphem Script Requests 1 04-28-04 07:55 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM


All times are GMT -5. The time now is 11:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.