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
  #11 (permalink)  
Old 09-27-06, 07:30 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
I'm not sure if that is possible. I think you have to click the browse button and select the file. I don't think you can set values with javascript to "file" inputs. That'd be a security hole if that would be possible.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #12 (permalink)  
Old 09-27-06, 07:35 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:
I don't think you can set values with javascript to "file" inputs.
I don't want to do this.

I have the following file fields:

Code:
<input type="file" name="userFile[]" size="20">   <!-- Need to send data to parent page hidden field 1 -->
<input type=file name=userFile[] size=20>  <!-- Need to send data to parent page hidden field 2 -->
I need to extract the selected file names and send the file names to corespondent hidden field on parent page.

With only one value work:

Code:
self.opener.document.foo.attach1.value = document.filesform.UserFile1.value;

and

<input type="file" name="userFile1" size="20"  >

Last edited by zoliky; 09-27-06 at 07:37 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #13 (permalink)  
Old 09-27-06, 07:59 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 have this HTML form:

Code:
<form name="filesform" action="files.php" method="post" enctype="multipart/form-data">

<table style="margin:1em 0 1em 0">
<tr valign="top" id="fileInput0"  >
<td><b>File 1:</b></td>
<td><input type="file" name="userFile[]" size="20" onkeypress="KeyPress()"  ></td>
</tr>
<tr valign="top" id="fileInput1"  >
<td><b>File 2:</b></td>
<td><input type=file name=userFile[] size=20 onkeypress="KeyPress()"  ></td>
</tr>
<tr valign="top" id="fileInput2"  >
<td><b>File 3:</b></td>

<td><input type=file name=userFile2 size=20 onkeypress="KeyPress()"  ></td>
</tr>
</table>
What I need to do to write each field value in Javascript. I have something like :

Code:
document.write(document.filesform.getElementsByTagName('input').value);
But JavaScript say is undefined. JavaScript need to get the selected file names and print :

file1.exe
file2.exe
file3.exe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #14 (permalink)  
Old 09-27-06, 03:44 PM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Unrealed wrote:

Quote:
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.
Ok I a modify each input field for different name.
But exist a way to manage this different names with php ?

I need to use PHP and JavaScript on page.

Thanks !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #15 (permalink)  
Old 09-28-06, 05:20 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
just store all the names of the input fields in an array, or if they have a logical name, you might wonna browse over them using a for loop.
either this:
PHP Code:

$fields = array('field_name1''field_name2''etc...');

for(
$i=0$i<sizeof($fields); $i++){
  
//do something with the input

or this:
PHP Code:

for($i=0$i<$number_of_fields$i++){

  
$input $_FILES['field'.$i];
  
//do something with the input

Hope this helps you,
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
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 10:51 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.