Help - Search - Members - Calendar
Full Version: saving contents of textarea
Weborum Webmaster Forum > Web Page Design > Javascript
CBrown
sorry if this question is stupid...

how would I save the contents of a textarea as a .htm file?

thanks
Joe
My guess would be to use PHP to set all entered data as a variable and then send it along to a text file (flat file) which is re-named to whatever.htm
Joe
PHP

<?php

$fp
= fopen("whatever.htm", "w") or die("Couldn't create new file");
$numBytes = fwrite($fp, "$inputvariable");

fclose($fp);
         
?>


Something like this if I'm not mistaken smile.gif
Willy Duitt
Save it where? Locally or on a server?
CBrown
locally
Willy Duitt
CODE

<script type="text/javascript">
<!--//
  function saveCode(what){
   var win = window.open('', '_blank', 'top=10000');
       win.document.open('text/html', '_blank');
       win.document.charset="iso-8859-1";
       win.document.write(what);
       win.document.execCommand('SaveAs',true,'formCode.html');
       win.close();
   }
//-->
</script>
</head>

<body>
<form style="text-align:center">
<textarea style="width:90%; height:90%" name="editor"></textarea>
<br><input type="button" value="Save" onclick="saveCode(this.form.editor.value)">
</form>


.....Willy
CBrown
Willy... you are my hero.

you wouldn't happen to know the code to open it again would you?
Willy Duitt
QUOTE(CBrown @ Dec 15 2004, 01:29 AM)
you wouldn't happen to know the code to open it again would you?
[right][snapback]20371[/snapback][/right]



Make up your friggin' mind biggrin.gif

CODE

<html>
<head>
<title>File System Object Example</title>
<script language="javascript">
<!--//
 var oFileSystem;
  oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
   function ShowFile(sFilePath){
     frmEditHTML.tarHTMLText.value = oFileSystem.OpenTextFile(sFilePath).ReadAll();
   }

   function SaveAfterEditing(){
    var oFile;
     oFile = oFileSystem.CreateTextFile(frmEditHTML.filPath.value,1);
     oFile.WriteLine(frmEditHTML.tarHTMLText.value);
     oFile.Close();
   }
</script>
</HEAD>

<BODY>
<b>Select the HTML File you want to Edit</b>
<form name="frmEditHTML">
<input type="file" name="filPath" onchange="ShowFile(this.value)">
<br><textarea name="tarHTMLText" cols=60 rows=20></textarea><br>
<input type="button" value="Save" name="cmdSave" onclick="SaveAfterEditing()">
</form>

</body>
</html>


.....Willy
CBrown
Willy... YOU are the master
deltacode
Hey just askin about this, if thts ok? Any way i was wondering how you would make a new file then be able to save it, along with the other parts, open,save and a new one if possible, can this be done?
-Many thanxs deltacode biggrin.gif
Willy Duitt
QUOTE(deltacode @ Dec 19 2004, 06:15 AM)
Hey just askin about this, if thts ok? Any way i was wondering how you would make a new file then be able to save it, along with the other parts, open,save and a new one if possible, can this be done?
-Many thanxs deltacode biggrin.gif
[right][snapback]20653[/snapback][/right]


Welcome to Weborum... biggrin.gif

Did you try running the above examples??
And if so, did you try adding them together on a page and target the same textarea??

.....Willy
deltacode
Thanxs biggrin.gif, Yeah i tried that but it it has no create new file method.
-deltacode
Willy Duitt
The first script creates a new file...
If you want to change or create the name, add a prompt...
deltacode
Well you know what youre talking about so would yo able to tell me how to do the following using this script?:
CODE

<html>
<script type="text/javascript" language="javascript">
 function saveCaret(elem) {
  if ( elem.isTextEdit )
elem.caretPos = document.selection.createRange();
 }
 
 function insertText(elem, wordInsert) {
  if ( elem.isTextEdit && elem.caretPos ) {
var bookmark = wordInsert;
var caretPos = elem.caretPos;
caretPos.text = bookmark;
 function Bold() {
  var formData = document.selection.createRange().text;
  if (formData != '') {
document.selection.createRange().text = '<b>'+formData+'</b>';
</script>
<INPUT onclick=Bold() type=button class=but value=bold ><br><TEXTAREA class=area name=message rows=20 cols=60 value="text" ></TEXTAREA>
</html>

This works but what i want it to do is, instead of using a button could i use a drop down menu to inser text?


Willy Duitt
QUOTE(deltacode @ Dec 23 2004, 01:16 PM)
Well you know what youre talking about so would yo able to tell me how to do the following using this script?:
CODE

<html>
<script type="text/javascript" language="javascript">
 function saveCaret(elem) {
  if ( elem.isTextEdit )
elem.caretPos = document.selection.createRange();
 }
 
 function insertText(elem, wordInsert) {
  if ( elem.isTextEdit && elem.caretPos ) {
var bookmark = wordInsert;
var caretPos = elem.caretPos;
caretPos.text = bookmark;
 function Bold() {
  var formData = document.selection.createRange().text;
  if (formData != '') {
document.selection.createRange().text = '<b>'+formData+'</b>';
</script>
<INPUT onclick=Bold() type=button class=but value=bold ><br><TEXTAREA class=area name=message rows=20 cols=60 value="text" ></TEXTAREA>
</html>

This works but what i want it to do is, instead of using a button could i use a drop down menu to inser text?
[right][snapback]20858[/snapback][/right]


Firstly, you are missing a closing brace in your Bold() function... And yes, you can use a dropdown menu by passing the value as an arguement to the function...

But, you have me completely confused here... What does this script have to do with saving and opening files on a local drive which is what this thread is about...

If you wish to discuss another script please start another thread to keep from confusing things further...

.....Willy
deltacode
Hello once again this time i was wondering if you could open a document withopught using the browse button just a standard button i thought u could do something like this:
CODE

<script type="text/javascript">
<!--//
 function saveCode(what){
  var win = window.open('', '_blank', 'top=10000');
      win.document.open('text/html', '_blank');
      win.document.charset="iso-8859-1";
      win.document.write(what);
      win.document.execCommand('Open',true,'formCode.html');
      win.close();
  }
//-->
</script>

is it like this and is it possible?

-Many thnxs deltacode.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.