Connecting Tech Pros Worldwide Forums | Help | Site Map

File read and write contents to text field

Newbie
 
Join Date: Dec 2007
Posts: 14
#1: Dec 11 '07
I have one text area and one button called import source code.When click on that button the text area named source code should get filled with the contents of the selected file.I have used browse button to select the file.How can i proceed now.Please help me.I need one java script for this.

Newbie
 
Join Date: Dec 2007
Posts: 14
#2: Dec 11 '07

re: File read and write contents to text field


I have one text area and one button called import source code.When click on that button the text area named source code should get filled with the contents of the selected file.I have used browse button to select the file.How can i proceed now.Please help me.I need one java script for this.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#3: Dec 11 '07

re: File read and write contents to text field


hi ...

what does the file contain? plain text?

kind regards
Newbie
 
Join Date: Dec 2007
Posts: 14
#4: Dec 12 '07

re: File read and write contents to text field


Quote:

Originally Posted by gits

hi ...

what does the file contain? plain text?

kind regards

Yes the file contains plain text.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#5: Dec 12 '07

re: File read and write contents to text field


in that case you could use a hidden iframe and set its location to the file-source ... so the text will be loaded into it. now you may use a function like the following to get the content of the txt-file:

Expand|Select|Wrap|Line Numbers
  1. function get_iframe_content(frame_name) {
  2.     // refer the frame by name and the frame's document
  3.     var doc = window.frames[frame_name].document;
  4.     return doc.firstChild.innerHTML;
  5. }
  6.  
and set that as the value of the textarea.

kind regards
Reply